-1

Just wondering what the best practice is for specifying an endpoint in rest to say "runSomeAction"? I'm aware of the uses for GET,POST,PUT,DELETE operations and using nouns to specify those endpoints, but what is the preferred method for exposing server functionality that isn't a CRUD type operation?

EDIT:

The result of the action will just kick off a process on the server and return a status of 200 immediately (before process is complete), no body. This process is specifically running some validation rules against saved items in a database.

weagle08
  • 1,763
  • 1
  • 18
  • 27
  • 1
    Does it have to be a REST API? This sounds much more like a job for a message queue or job scheduler. –  Mar 08 '16 at 17:13
  • who down-votes a legit question? lol to answer your question @MartinBroadhurst it does need to be in our API because the user is storing several objects and then would like the ability to kick off this process on demand. Results are reflected elsewhere in the UI, just doesn't have to be the current page or page we are redirecting too so that user can continue making other changes if desired. If I could change it I would, but this is going into legacy code and the requirement is in the contract and would cost too much to refactor to make this perform otherwise. – weagle08 Mar 08 '16 at 19:48

1 Answers1

1

What is the end result of the action? Typically, you do a PUT/POST to create the resulting resource. For instance, instead of POST /sendEmail, you'd do POST /email-notifications.

EDIT

In your case, I would consider your resource to be the results of the validation. I would suggest either POST /validations or POST /validations/{whateverTypeIsBeingValidated}. You could alternately go with validation-results. Even if you don't support the client viewing the validation results now, you have the option to do so later.

Also, per @MartinBroadhurst, a REST API may not be an ideal tool here.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52