-
Notifications
You must be signed in to change notification settings - Fork 0
Service
Pieter Verschaffelt edited this page Apr 21, 2019
·
2 revisions
The Service is very important in TypeScript REST Mapper and allows you to query REST API's directly. It supports reading from an API or storing and updating objects. The Service only requires a base URL for consuming API calls and automatically expands it to form the correct API endpoint. A Service follows these rules to compose endpoints automatically:
- The class name is automatically pluralized and appended to the end of the base URL, if no endpoint was specified by the user. If the base URL is
http://example.com, theService<Post>will use the endpointhttp://example.com/posts. - If the user specifies an endpoint explicitly, then this is the endpoint that will be appended to the base URL and that's used for requests.
Parameters:
-
x: (new () => T): Type of theEntityfor which a newServiceneeds to be instantiated. -
baseURL: string: Base URL for the REST API that should be queried using this newService. This corresponds to the root of the API in most cases. This URL will be supplemented with the correct endpoint path automatically, if you conform to the default implementation.
Retrieve one Entity of type T from the REST API. This method corresponds to performing a GET request on the associated endpoint of the API.
Parameters:
-
id: string = null: The id of the corresponding entity that should be retrieved from the REST API. -
params: object = {}: Additional URL query parameters that should be appended to the URL before performing the GET request. -
endPoint: string = null: TheServicepluralizes the encapsulatedEntity's name and appends it to the base URL by default. If you however decide to use a different name for yourEntitythan for your REST endpoint, you can override the default settings by passing the endpoint as this argument.
** This page is still under construction **