Home > Blockchain >  validate REST endpoint design
validate REST endpoint design

Time:06-02

REST endpoint design says: Not use verb

In an workflow-like create Employee which has multi-tab style like "Basic Details", "Educational Details", "Work Experience", etc... One first tab data is filled continue button is pushed resulting in an backend API call which just validates the detail in that tab and returns the list of validation errors if any or moves to next tab for the user to fill data. So basically this calls for validate API for each of the tabs with no intention of saving data. Now one thing that comes naturally is below:

POST /employee/basic/validate (removing api versioning details from endpoint for simplicity)

But using validate in API means verb. How to design then?

There's a separate flow where one can just save "basic details" of employee - so its like any normal API validate and save - so POST /employee/basic/ is good for that case.

CodePudding user response:

Seems that what you try to do in the end is to run your operation in dry-run mode.

My suggestion would be to add a dry-run option as request parameter for instance.

/employee/basic?dry-run=true

CodePudding user response:

REST endpoint design says: Not use verb

That's not a REST constraint - REST doesn't care what spellings you use for your resource identifiers.

All of these URL work, exactly the way that your browser expects them to:


Resources are generalizations of documents; the nature of the HTTP uniform interface is that we have a large set of documents, and a small number of messages that we can send to them.

So if you want a good resource identifier, the important thing to consider is the nature of the "document" that you are targeting with the request.

For instance, the document you are using to validate user inputs might be the validation policy; or you might instead prefer to think of that document as an index into a collection of validation reports (where we have one report available for each input).

  • Related