如何编写REST API? [英] How to write a REST API?

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

问题描述

我正在编写一个iPhone应用程序作为业余爱好项目,它需要一个Web服务来为其提供数据。它与我在工作中所做的并没有太大的不同,但在工作中我只写视图和控制器。其他人负责编写模型,通常客户端提供Web服务。

I'm writing an iPhone app as a hobby project and it will need a web service to provide it with data. It's not very different from what I do at work, but at work I only write views and controllers. Someone else is responsible for writing the model and usually the clients provide the web service.

我之前做过一些Web编程,当每个人都使用MySQL和PHP时,所以我的技能有点过时,但我相信我能够使用我已经知道的技术。但是,我不想浪费时间使用过时的工具。我已经发现最先进的技术是编写REST API。我认为应该有一些非常好的框架,只要你定义了一个模型,就会给你一个带有CRUD功能的REST API。

I have done some web programming before, back when everyone were using MySQL and PHP, so my skills are a bit outdated, but I'm confident that I would be able to pull it of using the techniques I already know. However, I don't want to waste my time using obsolete tools. I've figured out that the state of the art would be to write a REST API. I was thinking that there should be some pretty good frameworks out there that pretty much just gives you a REST API with CRUD functionality as soon as you've defined a model.

我想我的问题是:什么是启动和运行REST API的最快方法?我真的只想专注于编写iPhone应用程序,而不是花太多时间在这个API上。如果我能获得网络管理和修订历史,那将是很棒的。我还应该补充一点,API不应该是公开的,因此对身份验证的支持也很好。

I guess my question is: What would be the fastest way to get a REST API up and running? I really just want to focus on writing the iPhone app and not spend too much time on this API. It would be great if I could get web administration and revision history too. I should also add that the API isn't supposed to be public, so support for authentication would be great as well.

为了清楚起见。我不介意PHP框架。事实上它可能会更好,因为我知道我当前的托管支持它。

Just to be clear. I wouldn't mind a PHP framework. In fact it could possibly be better since I know that my current hosting supports it.

推荐答案

只是为了让你知道:

我最终使用Ruby on Rails。

I ended up using Ruby on Rails.

编辑:由于这个答案是因为没有提供选择Ruby on Rails的原因,也没有关于如何用它编写REST API的说明,我想我会给你我的动力和一些简单的指示。

Since this answer has been downvoted for not providing the reason behind choosing Ruby on Rails and also no instructions on how to write a REST API with it, I thought I would give you my motivation and some simple instructions.

我开始阅读一本关于Ruby on Rails的书,并意识到我需要做的就是使用脚手架,我免费获得了一个JSON REST API。

I started reading a book about Ruby on Rails and realized that all I needed to do was to use scaffolding and I got a JSON REST API for free.

这里是一个很好的指南,帮助您入门: http://guides.rubyonrails.org/getting_started.html

Here's a good guide to get you started: http://guides.rubyonrails.org/getting_started.html

当您的Ruby on Rails环境启动并运行时,创建REST API并不比运行更困难:

When you have your Ruby on Rails environment up and running, creating your REST API isn't harder than running:

$ rails generate scaffold Post name:string title:string content:text

(以上链接示例。)I还发现Rails非常容易并且可以自由地部署到 heroku ,这意味着我没有必要付费用于托管我非常基本的低流量REST API。还有很多其他原因让我非常乐意使用Ruby on Rails,但这超出了这个问题的范围。

(Example from the above link.) I also found that Rails is very easy and free to deploy to heroku, which meant that I didn't have to pay for hosting for my very basic, low traffic, REST API. There are many other reasons why I am very happy to work with Ruby on Rails, but that's beyond the context of this question.

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

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