Qwik City - Modify Data
NOTE: Not yet implemented.
Just like routes can define a way to fetch data, they can also define HTTP verbs to modify data. These are GET
, POST
, PUT
, PATCH
, DELETE
. We have already discussed the GET
verb in the previous section. Each of these verbs has a corresponding on___
method such as onGet
, onPost
, onPut
, onPatch
, and onDelete
.
// File: src/routes/product/[skuId]/details.js
import { EndpointHandler } from '@builder.io/qwik-city';
type EndpointData = ProductData | null;
interface ProductData {
skuId: string;
price: number;
description: string;
}
export const onPut: EndpointHandler<EndpointData> = async ({ params, request, response } ) => {
// put your DB access here, we are hard coding a response for the simplicity of this tutorial.
request; // <- read data from request and porform DB update.
response.headers.append('Cache-Control', 'no-cache, no-store');
return {
skuId: params.skuId,
price: 123.45,
description: `Description for ${params.skuId}`
};
};