Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] JSON Representations #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions examples/json-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"_links": {
"alternate": {
"href": "http://example.com/New+York+History?pw=3",
"type": "text/html"
},
"self": {
"href": "http://example.com/New+York+History?pw=3&format=hal%2Bjson"
},
"first": {
"href": "http://example.com/New+York+History?pw=1&format=hal%2Bjson"
},
"next": {
"href": "http://example.com/New+York+History?pw=4&format=hal%2Bjson"
},
"last": {
"href": "http://example.com/New+York+History?pw=42299&format=hal%2Bjson"
},
"search": {
"href": "http://example.com/opensearchdescription.xml",
"type": "application/opensearchdescription+xml"
}
},
"_embedded": {
"item": [
{
"title": "New York History",
"description": "... Harlem.NYC - A virtual tour and information on businesses ... with historic photos of Columbia's own New York neighborhood ... Internet Resources for the City's History. ...",
"_links": {
"self": {
"href": "http://www.columbia.edu/cu/lweb/eguids/amerihist/nyc.html",
"type": "text/html"
}
}
}
]
},
"opensearch": {
"totalResults": 4230000,
"startIndex": 21,
"itemsPerPage": 10,
"Query": [
{
"role": "request",
"searchTerms": "New York Histry",
"startPage": 1
},
{
"role": "correction",
"searchTerms": "New York History",
"startPage": 1
}
]
}
}
115 changes: 115 additions & 0 deletions opensearch-1-1-draft-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,54 @@ The following restrictions apply:
</html>
```

#### Autodiscovery in JSON

JSON resources may reference related [OpenSearch description
documents](#opensearch-description-document) via the hypermedia
element of the respective JSON hypermedia format.

##### Autodiscovery in HAL+JSON

HAL+JSON resources may reference related [OpenSearch description
documents](#opensearch-description-document) via the [HAL Draft 8 `Link`
object](https://tools.ietf.org/html/draft-kelly-json-hal-08#section-5).

The following restrictions apply:

- The `type` attribute must contain the value
`"application/opensearchdescription+xml"`.
- The link object must contain the key `"search"`.
- The `href` attribute must contain a URI that resolves to an OpenSearch
description document.
- The `title` attribute may contain a human-readable plain text string
describing the search engine.
- The Link object should include a `profile` link that contains
the value `"http://a9.com/-/spec/opensearch/1.1/"`.

*Example of a HAL+JSON resource that include OpenSearch audodiscovery link elements:*

```json
{
"_links": {
"profile": {
"href": "http://a9.com/-/spec/opensearch/1.1/"
},
"search": [
{
"title": "Content search",
"href": "http://example.com/content-search.xml",
"type": "application/opensearchdescription+xml"
},
{
"title": "Comments search",
"href": "http://example.com/comment-search.xml",
"type": "application/opensearchdescription+xml"
}
]
}
}
```

#### MIME type `application/opensearchdescription+xml`

For the purposes of RFC 4288 section 4.10 this specification contains the
Expand Down Expand Up @@ -1520,6 +1568,73 @@ profile associated with the [OpenSearch 1.1 namespace](#namespace):
</html>
```

### Response metadata in JSON

OpenSearch response metadata may be included in a JSON object via the "opensearch" element.

*Example of a page of search results in the HAL+JSON Draft-8 format*

```json
{
"_links": {
"profile": {
"href": "http://a9.com/-/spec/opensearch/1.1/"
},
"alternate": {
"href": "http://example.com/New+York+History?pw=3",
"type": "text/html"
},
"self": {
"href": "http://example.com/New+York+History?pw=3&amp;format=hal%2Bjson"
},
"first": {
"href": "http://example.com/New+York+History?pw=1&amp;format=hal%2Bjson"
},
"next": {
"href": "http://example.com/New+York+History?pw=4&amp;format=hal%2Bjson"
},
"last": {
"href": "http://example.com/New+York+History?pw=42299&amp;format=hal%2Bjson"
},
"search": {
"href": "http://example.com/opensearchdescription.xml",
"type": "application/opensearchdescription+xml"
}
},
"_embedded": {
"item": [
{
"title": "New York History",
"description": "... Harlem.NYC - A virtual tour and information on businesses ... with historic photos of Columbia's own New York neighborhood ... Internet Resources for the City's History. ...",
"_links": {
"self": {
"href": "http://www.columbia.edu/cu/lweb/eguids/amerihist/nyc.html",
"type": "text/html"
}
}
}
]
},
"opensearch": {
"totalResults": 4230000,
"startIndex": 21,
"itemsPerPage": 10,
"Query": [
{
"role": "request",
"searchTerms": "New York Histry",
"startPage": 1
},
{
"role": "correction",
"searchTerms": "New York History",
"startPage": 1
}
]
}
}
```

## Future Versions

This document is maintained at
Expand Down