Home correct way to have restful endpoints
Reply: 1

correct way to have restful endpoints

jsmean
1#
jsmean Published in 2018-02-13 20:57:36Z

I have the following endpoints, and I want them to be more restful. (maybe one post only but I am not sure)

.route('/xyz/:testId/report')
.post( testController.generateReport)  //automatically create file and 
                                        //update database, is this can be a get? as user is not posting any data

.route('/test/:testId/report/upload')
.post( testController.upload)  // user-client posting a report 

whats the best to remove

Quality Catalyst
2#
Quality Catalyst Reply to 2018-02-13 22:07:13Z

REST is resource based. Your two options have no resources in it and the APIs don't follow the guideline. It might pay to read it or run through a tutorial.

Posting a report RESTfully looks like this. Use plurals for your resources:

POST /users/{id}/reports

You select a specific user and post a new item into the reports collection. There is no such thing like action words in REST such as upload yet there are some edge situations when the guideline isn't specific enough and you may need to go down that path - typically in a PATCH case only.

Regarding POSTs and GETs: GET is used to get resources. Don't use it for creating data. POST is used to accept a resource you sent. PATCH is used to change an existing resource. See Wikipedia for a simple explanation of all the HTTP verbs available.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325274 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO