Navigator module for making API requests and controlling the responses.
npm install sioapi
Bundle
import SioApi from "sioapi";
CDN
import SioApi from "https://unpkg.com/sioapi";
Creates a new SioApi Object.
This module extends SioEvents.
-
Name Type Description url String Url of the API, leave blank to use current host. -
Check SioEvents for more details
Event Fire Time Data response Whenever a response from the server is received Call Object -
-
Creates a new Service Object to the API url/name
-
Sets a header to be send to every petition on this api.
-
Removes a header from the apis
-
- If subUrl is setted makes a GET fetch to API.url/subUrl with the options.
- If subUrl is not setted makes a GET fetch to API.url with the options. Returns a Call Object.
-
- If subUrl is setted makes a POST fetch to API.url/subUrl with the options and the body of data.
- If subUrl is not setted makes a POST fetch to API.url with the options and the body of data. Returns a Call Object.
-
- If subUrl is setted makes a PUT fetch to API.url/subUrl with the options and the body of data.
- If subUrl is not setted makes a PUT fetch to API.url with the options and the body of data. Returns a Call Object.
-
- If subUrl is setted makes a DELETE fetch to API.url/subUrl with the options and the body of data.
- If subUrl is not setted makes a DELETE fetch to API.url with the options and the body of data. Returns a Call Object.
-
Created from the call of an API.getService(name). This is used as a middleware between the apiurl and the service you're trying to fetch. Example: If API.url="https://example.com/api" A service can be: "users"
-
No documentation because this is not intended to be used directly. Call API.getService() instead.
-
Check SioEvents for more details
Event Fire Time Data response Whenever a response from the server is received Call Object -
-
Creates a new Service Object to the API url/name
-
Sets a header to be send to every petition on this Service.
-
Removes a header from the Service.
-
This is going to use the headers from the caller API and the headers from the Service.
- If subUrl is setted makes a GET fetch to API.url/${this.service}/suburl with the options.
- If subUrl is not setted makes a GET fetch to API.url/${this.service} with the options.
Returns a Call Object.
-
This is going to use the headers from the caller API and the headers from the Service.
- If subUrl is setted makes a POST fetch to API.url/${this.service}/subUrl with the options and the body of data.
- If subUrl is not setted makes a POST fetch to API.url/${this.service} with the options and the body of data.
Returns a Call Object.
-
This is going to use the headers from the caller API and the headers from the Service.
- If subUrl is setted makes a PUT fetch to API.url/${this.service}/subUrl with the options and the body of data.
- If subUrl is not setted makes a PUT fetch to API.url/${this.service} with the options and the body of data.
Returns a Call Object.
-
This is going to use the headers from the caller API and the headers from the Service.
- If subUrl is setted makes a DELETE fetch to API.url/${this.service}/subUrl with the options and the body of data.
- If subUrl is not setted makes a DELETE fetch to API.url/${this.service} with the options and the body of data.
Returns a Call Object.
-
Name | Type | Description |
---|---|---|
url | String | The url the request was made. |
headers | Object | Object with the headers of the response. |
blob | Blob | Blob of the body of the response. |
response | Response | A Response Object with a clone of the fetch response. |
status | Number | Number status of the response. |
ok | String | response.ok |
statusText | String | response.statusText. |
raw | Any | The computed raw data of the response. |
data | Any | The computed prefered type of the response (In case of the response being a json this is an object representation of that JSON). |
This fires the events "response" in the Service and in the API listeners. The listeners can change the final properties of this call.