RESTful means that the API is based on HTTP and stateless principles.
HTTP has a lot of different methods to make a call to a server. For example, when opening a website, the browser uses GET to get a resource. You can use GET to fetch data. However, if you want to push data to the server, HTTP provides other methods, like POST and PUT, depending on what you want to do. You can even call a web address with DELETE to remove data. Those are the most important methods.
In order to use the methods, you will want to make AJAX calls in the browser, or use the NodeJS request API. Both of them take the method as a string-parameter at some point. For example:
// create async server request object
const xhr = new XMLHttpRequest();
// specify HTTP method and URL
xhr.open('POST', 'example.com/some/rest/api/node');
// specify timeout in ms
xhr.timeout = 3000;
// react to timeout
xhr.ontimeout = () => console.error('TIMEOUT!');
// react to error while trying to connect to server
xhr.onerror = console.error;
// react to state change, for example success :)
xhr.onload = function() {
// only react to finished requests
if (this.readyState === 4) {
// if the server returned OK
if (this.status >= 200 && this.status < 300) {
// write response from server to console
console.log('SUCCESS: ' + this.response.toString());
// if the server returned ERROR
} else if (this.status >= 400) {
console.error('ERROR STATUS: ' + this.status.toString())
}
}
};
// finally, send the request. You can add data, if you want
xhr.send(JSON.stringify({ foo: 42, bar: 'Hello!' }));
The other thing, which is important for RESTful, is that the server does not store the client's state. The client will have to transmit everything the server needs to know in order to process a request on each and every request. That includes login information, tokens, data, etc. The server will do no magic and memorize anything for you. However, that should also be obvious from the documentation, which should include all the fields you have to send via the request.
REST is very useful, because it allows easy server-side logic and makes scaling a breeze, while still being super easy on the client side. Today, it still is the default way to build a stable web API, though some other strategies do exist.