What’s the best return code for “@unique” violations?

I would first consider 422 Unprocessable Entity: The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity, and the syntax of the request entity is correct but was unable to process the contained instructions. In this case, the contained instructions are “please create this new resource”. 409 Conflict … Read more

Error handling with Mongoose

If you’re using Express, errors are typically handled either directly in your route or within an api built on top of mongoose, forwarding the error along to next. app.get(‘/tickets’, function (req, res, next) { PlaneTickets.find({}, function (err, tickets) { if (err) return next(err); // or if no tickets are found maybe if (0 === tickets.length) … Read more

How do I access the HTTP request?

You can use the @Context annotation: @POST @Path(“/test”) @Produces(MediaType.APPLICATION_JSON) public String showTime( @FormParam(“username”) String userName, @Context HttpServletRequest httpRequest ) { // The method body }

How to send a message successfully using the new Gmail REST API?

got it! after reading the RFC 2822 specification I found out, that the complete message needs to be passed in the raw parameter, see the example: From: John Doe <[email protected]> To: Mary Smith <[email protected]> Subject: Saying Hello Date: Fri, 21 Nov 1997 09:55:06 -0600 Message-ID: <[email protected]> This is a message just to say hello. So, … Read more

what are REST,RESTFul, SOA and microservices in simple terms?

Disclaimer: most of this post is subjective. No attempt has been made here to strictly define anything, just trying to contextualize and give a global overview of the concepts and how they relate to each other. I thought I knew what REST/”RESTFul”, restfulservices, webservices, SOA and microservices I’d say that all these terms fall into … Read more

How to design REST API for email sending service?

The scheme you have given is correct. Alternatively you can use controllers to perform some more complex actions. In your case it can look like this: (action) (verb) (URI) (type) create: POST – /emails – collection retrieve: GET – /email/{id} – resource update: PUT – /email/{id} – resource delete: DELETE – /email/{id} – resource send … Read more

How to design REST API for non-CRUD “commands” like activate and deactivate of a resource?

How about coming up with a noun for the feature you want to modify – ‘status’ in this instance. This would then become a sub resource of the parent entity. So for your case I would model the URI as follows: /api/accounts/{accountId}/status If the ‘update’ semantics are idempotent then PUT would be most appropriate, else … Read more

Should the PATCH method return all fields of the resource in the response body?

Normally this should be handled through content negotiation. In other words, the client asks for a specific representation if it needs one. The request would look like this: PATCH /user/123 Content-Type: application/merge-patch+json Accept: application/vnd.company.user+json … In this case, the client expresses that it wants a full user representation as answer. Or it could do: PATCH … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)