Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
904e662f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
904e662f
编写于
1月 28, 2016
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Middleware have no plural
[ci skip]
上级
e9dff8e7
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
14 addition
and
14 deletion
+14
-14
guides/source/api_app.md
guides/source/api_app.md
+14
-14
未找到文件。
guides/source/api_app.md
浏览文件 @
904e662f
...
...
@@ -8,7 +8,7 @@ In this guide you will learn:
*
What Rails provides for API-only applications
*
How to configure Rails to start without any browser features
*
How to decide which middleware
s
you will want to include
*
How to decide which middleware you will want to include
*
How to decide which modules to use in your controller
--------------------------------------------------------------------------------
...
...
@@ -86,7 +86,7 @@ Handled at the middleware layer:
and return just the headers on the way out. This makes
`HEAD`
work reliably in
all Rails APIs.
While you could obviously build these up in terms of existing Rack middleware
s
,
While you could obviously build these up in terms of existing Rack middleware,
this list demonstrates that the default Rails middleware stack provides a lot
of value, even if you're "just generating JSON".
...
...
@@ -143,11 +143,11 @@ $ rails new my_api --api
This will do three main things for you:
-
Configure your application to start with a more limited set of middleware
s
-
Configure your application to start with a more limited set of middleware
than normal. Specifically, it will not include any middleware primarily useful
for browser applications (like cookies support) by default.
-
Make
`ApplicationController`
inherit from
`ActionController::API`
instead of
`ActionController::Base`
. As with middleware
s
, this will leave out any Action
`ActionController::Base`
. As with middleware, this will leave out any Action
Controller modules that provide functionalities primarily used by browser
applications.
-
Configure the generators to skip generating views, helpers and assets when
...
...
@@ -185,10 +185,10 @@ class ApplicationController < ActionController::API
end
```
Choosing Middleware
s
Choosing Middleware
--------------------
An API application comes with the following middleware
s
by default:
An API application comes with the following middleware by default:
-
`Rack::Sendfile`
-
`ActionDispatch::Static`
...
...
@@ -206,14 +206,14 @@ An API application comes with the following middlewares by default:
-
`Rack::ConditionalGet`
-
`Rack::ETag`
See the
[
internal middleware
s
](
rails_on_rack.html#internal-middleware-stack
)
See the
[
internal middleware
](
rails_on_rack.html#internal-middleware-stack
)
section of the Rack guide for further information on them.
Other plugins, including Active Record, may add additional middleware
s
. In
general, these middleware
s
are agnostic to the type of application you are
Other plugins, including Active Record, may add additional middleware. In
general, these middleware are agnostic to the type of application you are
building, and make sense in an API-only Rails application.
You can get a list of all middleware
s
in your application via:
You can get a list of all middleware in your application via:
```
bash
$
rails middleware
...
...
@@ -329,7 +329,7 @@ will be:
### Other Middlewares
Rails ships with a number of other middleware
s
that you might want to use in an
Rails ships with a number of other middleware that you might want to use in an
API application, especially if one of your API clients is the browser:
-
`Rack::MethodOverride`
...
...
@@ -340,13 +340,13 @@ API application, especially if one of your API clients is the browser:
*
`ActionDispatch::Session::CookieStore`
*
`ActionDispatch::Session::MemCacheStore`
Any of these middleware
s
can be added via:
Any of these middleware can be added via:
```
ruby
config
.
middleware
.
use
Rack
::
MethodOverride
```
### Removing Middleware
s
### Removing Middleware
If you don't want to use a middleware that is included by default in the API-only
middleware set, you can remove it with:
...
...
@@ -355,7 +355,7 @@ middleware set, you can remove it with:
config
.
middleware
.
delete
::
Rack
::
Sendfile
```
Keep in mind that removing these middleware
s
will remove support for certain
Keep in mind that removing these middleware will remove support for certain
features in Action Controller.
Choosing Controller Modules
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录