简体   繁体   中英

REST API - where to pass ID parameter? in URL or in header

I wrote a small web service with REST API and after reading a few tutorials I cannot come to a conclusive answer.

If I wish to pass a user id to the REST API, should I pass it in the URL like so:

127.0.0.1:8080/users?userid=716360178

Or like so:

127.0.0.1:8080/users/716360178

If I were to use the second one, how will I be able to retrieve the user ID from the URL? I'm using nodejs + express.

Please advise.

The second option you mentioned is the best way. Or at least the most conforming to the REST design.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM