Utils
Explanation
These utilities are the building blocks which are used throughout this library to create the methods for the Resource’s. You can use these functions to write your own Resource methods.
get
The get function does a GET request to the given url, with the query params if they are provided. It then passes along the result to the configured middleware for processing.
For example:
import { get } from '@42.nl/spring-connect';
get('/api/pokemon', { page: 1 }).then(json => {
// Do something with the json here
});
Note: that the second parameter can be left empty if you have no query parameters.
post
The post function does a POST request to the given url, with the given payload.
Then gives the result to the configured middleware
for processing.
post('/api/pokemon', { name: 'bulbasaur' }).then(json => {
// Do something with the json here
});
The payload can also be a FormData object, which is useful when uploading
files: See MDN.
put
The put function does a PUT request to the given url, with the given payload.
It then gives the result to the configured middleware for processing.
put('/api/pokemon/1', { id: 1, name: 'bulbasaur' }).then(json => {
// Do something with the json here
});
The payload can also be a FormData object, useful for when uploading
files: See MDN.
patch
The patch function does a PATCH request to the given url, with the given payload.
Then gives the result to the configured middleware
for processing.
patch('/api/pokemon/1', { id: 1, name: 'bulbasaur' }).then(json => {
// Do something with the json here
});
The payload can also be a FormData object, useful for when uploading
files: See MDN.
remove
The remove function does a DELETE request to the given url.
Then gives the result to the configured middleware
for processing.
import { remove } from '@42.nl/spring-connect';
remove('/api/pokemon/1').then(() => {
// Do something here.
});