What is better to do when you need a verb using a REST api?

I am showing a REST API, and it is surprisingly easy and smooth to work while you execute CRUD (Create, Update, Delete). But I have these Tickets that return a list of tickets (get), Ticket / {id} that get a specific item (get) and an activation method (put) that change the ticket status from not activated for activation.

Now I need to give the REST consumer the opportunity to do something like (in ws it will be called: GetAndActivateRandomTicket (), and this makes me wonder what it should be described as on REST? It post "a put? A get". The goal is in order to get a random number of tickets and assign the status to active, something like get and put at the same time, but not knowing the {id} for put in front of him.

Must be / Tickets? activate = true & amount = 5? Which verb? Should I put out a verb instead of a noun? What are the "best practices" on this issue?

Thank.

+5
source share
4 answers

I extracted this:

Everything that can be created as a resource, including transactions, sessions and other similar objects without a domain :)

and went with:

TicketActivation Resource.

[POST] with the parameter request amount will return a set of random tickets. and return the resource URL in such a way that you can get as / ticket / id = 1,2,3,4,5 [GET] will return tickets as usual with an additional id filter to return multiple tickets [PUT] will also use the id filter and set to true or false depending on the parameter.

so that I can:

[post]
/ticket/activation/?amount=5
Return resource

- /ticket? id = 1,2,3,4,5 .

[get]
/ticket?id=1,2,3,4,5

[put]
/ticket/activation?id=1,2,3,4,5&deActivate [OR]
/ticket/activation?id=1,2,3,4,5&activate

, , RESTfull , . , , , .

+1

- (, ), . POST ( ) RESTful.

+4

. , , , . ROA (- ) . , , , , :)

"" - . , "" , , .

, , - - () " " ?

, , - , : URL- URL-:

  • /Tickets? amountToActivate = 5; ( "" )
  • /Tickets? amountToActivate = 5 & activate = true (: , , = true , URI, = true - "" URL ( true) false:)

IS , URL- URL, = true , . , '&'

:

  • GET:/? fetchRandomAmountOfTickets = 100 ( )
  • PUT:/Tickets ( "" PUT , "GOT" ).

, :)

+3

, GET . PUT.

What I would do is create a resource URL, for example / Tickets / Random, which as a result of GET returns HTTP 303 to redirect the user to a randomly determined actual resource URL, for example / Tickets / 12345. Then the user can activate this ticket using PUT . The entire user application should know this is / Tickets / Random URL, and it can continue to activate tickets as long as they are.

+2
source

All Articles