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.

These paths may vary according to the needs of each one and are here only as a suggestion. With a little experience it is possible to understand what is being done and use it as you see fit

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.

CategoryService.js
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.

This class will be used next to provide access to the entity's endpoints, let's move on to the next step.

Defining the schema

Last updated

Was this helpful?