在 REST api 中如何处理 URI? [英] How are URI's handled in a REST api?

查看:38
本文介绍了在 REST api 中如何处理 URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个业余爱好 iOS 应用程序,但我对如何为其创建 REST 后端感到有些困惑.我已经阅读了互联网上可用的资源,并且了解了 REST 背后的理论.但是,我对如何处理 URI 感到困惑.例如,是否有文件处理/resource/或/resource/{id} 中的其余函数,或者这些文件是否位于根目录下,不知何故 URI 调用被路由到它们?请原谅我对网页设计的无知.

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.

推荐答案

这取决于服务器架构.将单独的 CGI 文件放在适当的文件夹中并处理请求是完全合法的,也许结合一些 URL 重写以获得漂亮的 URL.

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.

另一方面,大多数现代 Web 框架都有某种 URL 调度程序.这是框架的核心组件,负责将请求分派(= 映射)到各种代码段(通常是类和方法).

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).

例如,有一个名为 Mojolicious 的现代 Perl 框架.即使不了解任何 Perl,您也可能会发现它的关于路由的文档很有趣,因为它很好地回答了您的问题.

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.

这篇关于在 REST api 中如何处理 URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆