Preparing API access
Front-end applications needing to communicate with services that deliver data and generally these services use HTTP
Following our example, let's create a folder calledSchemainsidesrc/domains/General/Category. Within this folder, create a file calledCategoryService.js, with asrc/domains/General/Category/Schema/CategoryService.js path at the end.
The content of this document will be a class similar to the excerpt below. When extending theRestclass, theCategoryServiceclass inherits all of its behavior. These behaviors include methods that create, read, update and delete resources from theCategoryentity.
import Rest from 'src/app/Services/Rest'
import { resource } from 'src/domains/General/Category/settings'
/**
* @class {CategoryService}
*/
export default class CategoryService extends Rest {
/**
* @type {string}
*/
resource = resource
}Note the use of theresourceproperty that is imported from settings.js. To know more details about Serviceswithin the project visit this page.
There is no class to consume resources using GraphQL,but the logic is basically the same and with some knowledge of JavaScript it is possible to create an abstraction for this type of service as well.
This class will be used next to provide access to the entity's endpoints, let's move on to the next step.
Defining the schemaLast updated
Was this helpful?