简体   繁体   English

如何存储REST资源

[英]How to store REST resources

So I've been reading up on the REST architectural style and I think I grasp the general concept. 因此,我一直在阅读REST架构风格,我认为我掌握了总体概念。 However, I am having a hard time understanding how the resources are stored (which seems like a very important concept..). 但是,我很难理解资源的存储方式(这似乎是一个非常重要的概念。)。

So for example, I understand that I can have a homepage, say index.html, and on that page I can have a link to get a list of items. 例如,据我了解,我可以有一个主页,例如index.html,在该页面上,我可以有一个链接以获取项目列表。 So the homepage is: 因此主页是:

http://localhost/index.html

and then to get the list of items you send a GET request to: 然后要获取项目列表,请将GET请求发送至:

http://localhost/items

if I'm correct this far, then how do you store the list of items at that location? 如果到目前为止我是正确的,那么您如何在该位置存储项目列表? Is it just a text file of all the items in JSON format? 它只是所有项目的JSON格式的文本文件吗?

Thank you for any input! 谢谢您的投入!

You store them in any way you like. 您可以用任何喜欢的方式存储它们。 A relational database is not uncommon. 关系数据库并不罕见。 A JSON data file is possible (but nowhere near as flexible or safe). 可以使用JSON数据文件(但远没有那么灵活或安全)。

When it is requested, you fetch the data from where ever you stored it and then express the resource in any way you like. 当请求时,您可以从存储位置获取数据,然后以自己喜欢的任何方式表示资源。 JSON or XML are not uncommon. JSON或XML并不少见。

A web server does not necessarily need to interpret a URI as a folder structure that is available on some disk. Web服务器不一定需要将URI解释为某些磁盘上可用的文件夹结构。 There are a lot of frameworks that let you freely define your routes which allows you to execute arbitrary code whenever a route is hit. 有许多框架可让您自由定义路由,使您可以在命中路由时执行任意代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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