本文介绍了在 Rails 上构建 REST Web 服务的教程或截屏视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 Rails 上构建一个 REST 网络服务,作为我的移动应用的服务器端组件.有人可以指出一些关于为正在学习 Rails 的人构建 REST 网络服务的教程截屏视频吗?

I am looking to build a REST webservice on Rails to serve as the server side component to my mobile app. Can someone point out some tutorials or screencasts on building REST webservices for someone who is learning Rails?

我正在寻找的主要功能是:

The main features I am looking for are:

  1. 授权(用户 ID 和密码验证).
  2. 使用 REST API 将数据从客户端(移动应用)发布到服务器数据库

如果你能指点我一些关于创建 rest api 的内容可用的书,我也可以.

I am also okay if you could point me to some book where content on creating a rest api is available.

如果有人能发布一些代码让我开始做这件事也很棒.

It would also be great if someone could post a bit of code to get me started on this.

我对 Rails 比较陌生,几乎完成了 Michael Hartl 所著的Ruby on Rails 教程"一书.到目前为止,这是我对 Rails 的唯一体验.

I am relatively new to Rails and have almost finished the book "Ruby on Rails Tutorials" by Michael Hartl. This is my only experience with Rails, so far.

谢谢.

推荐答案

我写了 2 篇博文,你可能会觉得有帮助:

I wrote 2 blog posts that you'll probably find helpful:

http://davidsulc.com/blog/2011/04/10/implementing-a-public-api-in-rails-3/

http://davidsulc.com/blog/2011/04/17/sumption-a-public-rails-api-with-jquery/

它们不是教程,但应该可以帮助您入门.

They're not tutorials, but it should get you going.

基本思想是:当使用 .json 格式发出请求时,通过控制器操作公开 JSON 数据.

The basic idea is: expose JSON data through controller actions when a request is made with the .json format.

跨域请求(例如您将在移动应用中执行的请求)有点棘手,如博客文章中所述:您实际上需要在回调中发送 javascript,否则您的代码将不会工作(你会得到一个空的回应).(在第一篇文章中解释过.)

Cross domain requests (like the ones you'll be doing from your mobile app) are a little trickier, as explained in the blog post: you'll actually need to send javascript within a callback, or your code won't work (you'll get an empty response). (Explained in the first post.)

一旦数据以 JSON 形式公开,只需从您的移动应用中查询它(如第二篇文章中所述).

Once the data is exposed as JSON, simply query it from your mobile app (as explained in the 2nd post).

Manning 有一本关于 Rails 3 的书(其中一位作者正是 Yehuda Katz),其中有一章关于创建 API:http://manning.com/katz/ 特别是,它涵盖了使用 Devise 的 API 的令牌授权.

Manning has a book on Rails 3 (one of the authors being none other than Yehuda Katz) with a chapter on creating an API: http://manning.com/katz/ In particular, it covers token authorization for the API using Devise.

这篇关于在 Rails 上构建 REST Web 服务的教程或截屏视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:27