Standardization in building Rest api with Vraptor

Asked

Viewed 106 times

2

Well I have a question about standardization in the creation of Rest endpoints. According to Vraptor documentation I can set the request path using the annotation > @Path("/paciente-api") here at the company this is the standard , but I have noticed some classes where the path ends with / , what a difference it would make in the end?
Requests are also noted, for example> @Get("/"), here’s where my biggest question goes, following this logic my request would be a GET to localhost:8080/system/patient-api/ , until then everything ok, but when I have to send parameters the STATUS CODE is 405, because this happens is an error in my backend or the request ?

2 answers

2


Isaiah, this path question, if you put the bar at the end, you should use it with the bar where you call. That is, if you have the annotation with @Path("/paciente-api"), there in the requisition should be http://localhost:8080/sistema/paciente-api.

But in the vraptor documentation you have a Cookbook to accept with or without bar, follow the link http://www.vraptor.org/pt/cookbook/aceitando-urls-com-ou-sem-barra-no-final/

Just as / upper or lower case letters also differentiate, so in my paths, I never use / at the end and capital letters.

Probably gave 405 because it had some other route @Post or such for this path with / in the end, I can help more with this part if you give more details.

  • I noticed that the request ignored / when it went with parameters, leaving the url like this : http://localhost:8080/system/patient-api? name=xxx , when I put / at the end of the path the request finds its path. , but I get this question about good practices when creating a Rest api. Where is my error, in the documentation that should have been clear, or in the standardization of the address, with or without /, understand?

  • It’s not enough to be so much Vraptor, because whenever we talk about REST, we’re basically talking about it. REST we will usually use the correct HTTP methods (GET, POST, PUT, DELETE), but Vraptor, by own experience, understands very well GET and POST, so I turn around with them only. In general, if I don’t want to update use information get, if I don’t use post.

  • As for the routes I use, for example: (get) /users - list users (get) /users/1 - detail user (post) /users - create user (get) /users/1/edit - update user (post) /users/edit - update user (here would be put, but vraptor has to pass an extra parameter to be put, this gives problem when sending file, so never use) (get ) /users/1/remove - remove user

  • if I need to pick up a user’s groups I’ll use route /users/1/groups and so on... I don’t know if I’m getting to the part you’re questioning, anything tells me

2

1. You note your method with:

Requests are also noted, for example> @Get("/")

2. Tries to send parameters on request and receives 405 status in response:

but when I have to send parameters the STATUS CODE is 405


  • Apparently he’s trying to accomplish a POST in a method that expects a request of type GET. Try to change the annotation of your method of @Get("/") for @Post("/").

Take a look at the documentation regarding HTTP request methods and HTTP response status codes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.