Skip to content

Commit

Permalink
翻译“Extending”
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac committed Oct 12, 2014
1 parent 7914c26 commit d693600
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions extending/index.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
---
layout: page
title: Extending
title: 扩展
---

{% include status.md %}

## Extending <a href="#extending" id="extending" class="headerlink"></a>
## 扩展 <a href="#extending" id="extending" class="headerlink"></a>

If you would like to extend JSON API, you may do so with the profile link
relation, defined in [RFC 6906](http://tools.ietf.org/html/rfc6906). See also
[this blog post by Mark
Nottingham](http://www.mnot.net/blog/2012/04/17/profiles).
如果你想扩展 JSON API,你应该遵循 [RFC 6906](http://tools.ietf.org/html/rfc6906) 定义的 profile。
另请参阅 [Mark Nottingham 写的这篇文章](http://www.mnot.net/blog/2012/04/17/profiles)

The `meta` key is where this profile link SHOULD go.
`meta` 部分定义了 profile 的链接。

Note that according to the RFC, profiles are
**注意**,在 RFC 规范中,profile:

```
defined not to alter the semantics of the resource representation itself, but
to allow clients to learn about additional semantics (constraints, conventions,
extensions) that are associated with the resource representation, in addition
to those defined by the media type and possibly other mechanisms.
```
> 不改变资源表示的语义定义本身,但让客户了解更多的语义(约束、规范、扩展)相关联的资源表示形式,
> 还有这些定义的媒体类型和可能的其他机制。
## Examples <a href="#examples" id="examples" class="headerlink"></a>
## 示例 <a href="#examples" id="examples" class="headerlink"></a>

For example, let's say that you want your API to support a different pagination
scheme, such as one based on cursors. You would make some sort of profile page
on your site, such as `http://api.example.com/profile`, and then include it
in the `meta` key of your responses:
例如,假设你想让你的 API 支持不同的分页设计,如基于游标。
你会制作某种信息页面在你的网站上,如 `http://api.example.com/profile`
然后会响应中包含 `meta` 键:

```text
GET http://api.example.com/
```

```json
{
"meta": {
"profile": "http://api.example.com/profile"
},

"posts": [{
// an individual post document
// 一份单独的文档
}]
}
```

That document will de-reference to explain your link relations:

这份文档将解释链接之间的关系:

```text
GET http://api.example.com/profile HTTP/1.1
```

```text
HTTP/1.1 200 OK
Content-Type: text/plain
```

The Example.com API Profile
===========================

The Example.com API uses cursor-based pagination. Here's how it works: in the
`meta` section of responses, it will return a `cursors` relation, with
`after`, `before`, and `limit` relations that describe the cursors. You can use
these with the URI template given in the `href` relation to generate the URIs
you need to paginate.
Example.com API 使用基于游标的分页。
它是这样工作的:
在想要的 `meta` 部分,它将返回一个 `cursors` 的关系(relation),
其中包括 `after``before``limit`,用来描述该游标。
您可以使用 `href` 给出的 URI 模板来生成分页的 URIs。

```json
"meta": {
"cursors": {
"after": "abcd1234",
Expand Down

0 comments on commit d693600

Please sign in to comment.