Skip to content
On this page

CRUD

This type of service are supposed to expect an other endpoint to concat the baseURL provided at the service creation. e.g.:

import { createCRUD } from "@vue-cruder/core";
const services = createCRUD({
  baseURL: "https://your-general-endpoint.com/api",
});

Create

Performs a POST

service.create(endpoint, object);

Params

paramtypeDescriptionRequired
endpointstringendpoint to be concatenated to the urlyes
objectobjectObject to be send at body of the requestyes

Usage

const response = await service.create("user", {
  name: "Will",
  age: 12,
});

Concatenating the URL and so making a HTTP POST Request to the full URL https://your-general-endpoint.com/api/user

Read

Performs aGET for a list or a single record.

service.read(endpoint, args);

Params

paramtypeDescriptionRequired
endpointstringendpoint to be concatenated to the urlyes
argsstring orobjectCan be and id string, empty, or a params objectno

Usage

service.read("user");

Concatenating the URL and so making a HTTP GET Request to the full URL https://your-general-endpoint.com/api/user

service.read("user", "13de-3fvf-vf4g");

Final URL https://your-general-endpoint.com/api/user/13de-3fvf-vf4g

service.read("user", { page: 1, orderBY: "name" });

Final URL https://your-general-endpoint.com/api/user?page=1&orderBY=name

Update

Performs a PUT

service.update(endpoint, id, object);

Params

paramtypeDescriptionRequired
endpointstringendpoint to be concatenated to the urlyes
idstringid of the record, or a empty stringyes
objectobjectcontent to be updateyes

Usage

service.update("user", "1", {
  name: "Margie",
  age: 11,
});

service.update("updateValue", "", { id: 4, brand: "Ford", age: 11 });

Concatenating the URL and so making a HTTP PUT Request to the full URL https://your-general-endpoint.com/api/user/1 with a body.

Delete

Performs a DELETE

service.delete(endpoint, id);

Params

paramtypeDescriptionRequired
endpointstringendpoint to be concatenated to the urlyes
idstringid of the recordyes

Usage

service.delete("user", "autogenerate-id");

Concatenating the URL and so making a HTTP DELETE Request to the full URL https://your-general-endpoint.com/api/user/autogenerate-id