I have a web applications where the user can upload samples that can be processed by the backend. Each sample can have one or more files of different types. Once the information about the sample is uploaded the user can request the sample to be analysed either immediately or later (the analysis can take hours in some case). The backend is based on REST services.
How do I tell the backend to start the analysis? One of the REST principle that the URLs should be based on noun.
So I cannot use
/startAnalysis?sampleId=55&startTime=now
What about cancelling the analysis?
/cancelAnalysis?sampleId=57
Actually you are "allowed" to have API calls that send a response that is not a resource, they are called Actions and when dealing with REST Actions you have to use verbs and not nouns.
For example, a REST API to convert 100 euros to Chinese Yen:
`/convert?from=EUR&to=CNY&amount=100`
Thus your REST actions startAnalysis
and cancelAnalysis
are valid.
I recommend you to read Web API Design (free eBook) by apigee which is a lovely short introduction to REST API design. It also covers REST Actions.
You can also imagine that the 'start of the analysis' is part of the state of your Analysis resource. And instead of using actions you can use PATCH or PUT to update the state of your Analysis resource.
And a more elaborated solution could be :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With