How are URI's handled in a REST api?

纵然是瞬间 提交于 2019-12-24 06:58:16

问题


I'm creating a hobby iOS app, and I'm a bit confused about how to create a REST backend for it. I've read the resources available on the internet and I understand the theories behind REST. However, I'm confused about how the URI's get handled. For instance, is there a file handling rest functions at /resource/ or /resource/{id} or are these files sitting at root, and somehow the URI calls are getting routed to them? Excuse my ignorance at web design.


回答1:


That depends on the server architecture. It’s perfectly legal to have only separate CGI files sitting in appropriate folders and handling the requests, maybe in conjuction with some URL rewriting to have nice URLs.

On the other hand most modern web frameworks have some kind of URL dispatcher. That’s a core component of the framework, and it takes care of dispatching (= mapping) requests to various pieces of code (usually classes and methods).

There’s for example a modern Perl framework called Mojolicious. Even without knowing any Perl you might find its documentation about routing interesting, for it answers your question quite well.



来源:https://stackoverflow.com/questions/7518835/how-are-uris-handled-in-a-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!