Github API v3-Overview-Media Types

来源:互联网 发布:java 相同签名的方法 编辑:程序博客网 时间:2024/04/29 15:58

Media Types 媒体类型

  • Comment Body Properties
  • Git Blob Properties
  • Commits, Commit comparison, and Pull Requests
  • Repository contents
  • Gists

Custom media types are used in the API to let consumers choose the format of the data they wish to receive. This is done by adding one or more of the following types to the Accept header when you make a request. Media types are specific to resources, allowing them to change independently and support formats that other resources don’t.

定制的媒体类型会在api中用到,让用户自己选择他们需要的时间 格式。使用方法是在请求的Accept字段后加一个或或多个类型格式。媒体类型是针对资源的,可以让某一个资源独立改变或支持你需要的格式而其他的资源格式不变。

All GitHub media types look like this:

所有的GitHub 媒体类型都是像下面这样的:

application/vnd.github[.version].param[+json]

The most basic media types the API supports are:

大多数的媒体类型api支持下面的格式

application/jsonapplication/vnd.github+json

Neither of these specify a version, so you will always get the current default JSON representation of resources.

所有的这些都没有指定,这样你就可以总是获取默认的代表资源的JSON字符串。

Important: The default version of the API may change in the future. If you're building an application and care about the stability of the API, be sure to request a specific version in the Accept header as shown in the examples below.

特别注意:默认版本的api获取会在未来改变,如果你创建的程序非常注重api的稳定性,请确认你你在请求头的Accept字段指定了版本,像下面的例子一样。


You can specify a version like so:

你可以指定一个版本像这样:

application/vnd.github.v3+json

If you’re specifying a property (such as full/raw/etc defined below), put the version before the property:

如果你在指定一个属性(例如full/raw/etc ,像下面这样定义的),请把版本放在属性前面:

application/vnd.github.v3.raw+json

You can check the current version through every response’s headers. Look for the X-GitHub-Media-Type header:

你可以在每一个响应头查看当前版本,请查看响应头的X-GitHub-Media-Type字段

$ curl https://api.github.com/users/technoweenie -IHTTP/1.1 200 OKX-GitHub-Media-Type: github.v3$ curl https://api.github.com/users/technoweenie -I \  -H "Accept: application/vnd.github.full+json"HTTP/1.1 200 OKX-GitHub-Media-Type: github.v3; param=full; format=json$ curl https://api.github.com/users/technoweenie -I \  -H "Accept: application/vnd.github.v3.full+json"HTTP/1.1 200 OKX-GitHub-Media-Type: github.v3; param=full; format=json

Comment Body Properties 评论体属性

The body of a comment can be written in GitHub Flavored Markdown. Issues, Issue Comments, Pull Request Comments, and Gist Comments all accept these same media types:

评论的内容可以在GitHub Flavored Markdown书写。提问,回复提问,推送评论请求,和根据评论接受相同的媒体类型:

Raw

application/vnd.github.VERSION.raw+json

Return the raw markdown body. Response will include body. This is the default if you do not pass any specific media type.

返回raw markdown内容。响应会包含body字段。如果你没有指定媒体类型那么下面是默认的。

Text

application/vnd.github.VERSION.text+json

Return a text only representation of the markdown body. Response will include body_text.

返回的内容代表了markdown 内容,响应会包含body_text

HTML

application/vnd.github.VERSION.html+json

Return HTML rendered from the body’s markdown. Response will include body_html.

markdown的内容返回HTML渲染内容,响应会包括body_html字段

Full

application/vnd.github.VERSION.full+json

Return raw, text and HTML representations. Response will include bodybody_text, and body_html:

返回一个原始的,文本的,HTML的代表。响应会包括bodybody_text, and body_html:

Git Blob Properties

The following media types are allowed when getting a blob:

当获取博客的数据时你会得到下面的媒体类型

JSON

application/vnd.github.VERSION+jsonapplication/json

Return JSON representation of the blob with content as a base64 encoded string. This is the default if nothing is passed.

返回以base64 编码的博客内容的字符串,如果没有指定,这是默认的。

Raw

application/vnd.github.VERSION.raw

Return the raw blob data.

返回原始的博客数据

Commits, Commit comparison, and Pull Requests 提交,提交对比,推送请求。

The Commit, Commit Comparison, and Pull Request resources support diff and patch formats:

提交,头角对比,推送请求资源支持的和混合的格式:

diff 

application/vnd.github.VERSION.diff

patch

application/vnd.github.VERSION.patch

Repository contents 仓库内容

Raw

application/vnd.github.VERSION.raw

Return the raw contents of a file. This is the default if you do not pass any specific media type.

返回一个文件的原始内容,如果没有指定任何内容这是默认的格式。

HTML

application/vnd.github.VERSION.html

For markup files such as Markdown or AsciiDoc, you can retrieve the rendered HTML using the .html media type. Markup languages are rendered to HTML using our open-source Markup library.

对于标记文件,例如Markdown 或者AsciiDoc,你可以你可以使用.HTML媒体类型检索渲染的html。标记语言使用开源的Markup library.渲染html。

Gists

Raw

application/vnd.github.VERSION.raw

Return the raw contents of a gist. This is the default if you do not pass any specific media type.

返回gist的原始内容,如果没有指定任何内容这是默认的格式。

base64

application/vnd.github.VERSION.base64

The gist contents are base64-encoded before being sent out. This can be useful if your gist contains any invalid UTF-8 sequences.

gist内容被发送前使用base64格式编码,如果你的gist内容包含任何UTF-8序列,这是十分有用的。

0 0