0

First of all have a nice weekend for those who are! For the other good luck :)

I am creating an app using rest architecture.

I just have a simple question but I don't know how to explain it.

So let's take an example and maybe the question will come after.

Imagine you have a path element called Car. If I do a GET on it it returns the carInformation

So I would define:

@GET
@Path("/car/{carid}/display")
public Response getCar(@PathParam("carid")String carID)

If I define actions to perform on this car like open, close, start etc:

@POST
@Path("/car/{carid}/startup")
public Response startup(@PathParam("carid")String carID)

@POST
@Path("/car/{carid}/open")
public Response open(@PathParam("carid")String carID)

@POST
@Path("/car/{carid}/close")
public Response close(@PathParam("carid")String carID)

Is there a common check done at /car/{carid} like "is it my car?" "is it in the garage?" or do I have to implement it with abstraction for example between the process which will be called after

In fact I am not understanding the real goal of path param. Why don't do simply

@GET
@Path("/car/displayCar")
public Response getCar(@QueryParam("carid")String carID)

@POST
@Path("/car/startup")
public Response startup(String carID)

@POST
@Path("/car/{carid}/open")
public Response open(String carID)

@POST
@Path("/car/{carid}/close")
public Response close(String carID)

Thanks all for you answer in advance

Best regards

Geoffrey MUSELLI

Gandalf
  • 9,648
  • 8
  • 53
  • 88
Geoffrey
  • 1,151
  • 3
  • 13
  • 26
  • So, for starters, this isn't a knock - just a clarification. If you are defining actions in your URL then you are, in general, not designing a RESTful API. You are talking RPC (not a bad thing, necessarily, just a difference in terminology. – Gandalf Sep 02 '16 at 21:26

1 Answers1

0

There are a lot of ways to go at this, both REST and RPC - and I'm not here to say which is better (you need to evaluate which would be easier/better/etc for the consumers of your API [IMO]). For this I am going to go at it using a REST approach.

For displaying a single car's info there is no need for an endpoint ending in 'display'. A GET request to /car/{car id} is sufficient. That document can have things like the car's current state (open, closed, running, exploded, etc . . .) The GET is your action, the /car/{car id} is your thing, and the document it returns (and excepts via POST or PUT are the protocol of your API)

Gandalf
  • 9,648
  • 8
  • 53
  • 88