I would like to know if there is a way to returns a specific HTTP status code from within a remote method.
I can see that there is a callback function which we can pass an error object, but how do we define the HTTP status code?
To get the status code of an HTTP request made with the fetch method, access the status property on the response object. The response. status property contains the HTTP status code of the response, e.g. 200 for a successful response or 500 for a server error.
To set a different HTTP status code from your Servlet, call the following method on the HttpServletResponse object passed in to your server: res. setStatus(nnn); where nnn is a valid HTTP status code.
A remote method is a method of a model, exposed over a custom REST endpoint. Use a remote method to perform operations not provided by LoopBack's standard model REST API. Note: The easiest way to define a remote method is by using the command-line remote method generator.
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
You can return any status code just like you would in ExpressJS.
...
res.status(400).send('Bad Request');
...
See http://expressjs.com/api.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With