Skip to content

Latest commit

 

History

History
295 lines (176 loc) · 6.82 KB

spore_description.pod

File metadata and controls

295 lines (176 loc) · 6.82 KB

NAME

Spore (Specifications to a Portable REST Environment) Description Implementation

ABSTRACT

Spore is a specification for describing HTTP APIs which happen to suffice some constraints laid out by the REST architectural style. It can be parsed and used automatically by client implementations to communicate with the described API.

This document describes how to write the description for such an API in order to be used with a SPORE Client Implementation.

TERMINOLOGY

API

An API is the interface to an application that can exchange data with client applications over HTTP/HTTPS. It presents one or more method endpoints which accept HTTP requests with varying headers, parameters and body content to perform specific operations.

Client Implementation

A Client Implementation is a library targeting a specific system or language. It can use Descriptions files to create programmatic interfaces usable in applications.

Description File

A Description File is a file in JSON format describing an API (see specification). It can directly be used by a Client implementation to create a programmatic interface in the target system.

Payload

The Payload is the data sent in the body of a POST or PUT request. The Payload is unrelated to method parameters defined herein.

Format

The Format is the kind of data serialization used for the Payload.

API DESCRIPTION

An API should provide a description file, in JSON format, that conforms with this description.

GENERIC DESCRIPTION

This part describes the overall API and provides some default values for the individual method descriptions.

name

A required simple name to describe the specification

"name" : "CouchDB"

authority

An optional authority of the description

"authority" : "GITHUB:franckcuny"

base_url

An optional base URL for the API

"base_url" : "http://api.twitter.com/1/"

formats

A list of supported formats

"formats" : [
  "json"
  "xml"
]

version

A mandatory version number of the SPORE description of the API, expressed as a string

"version" : "0.1"

authentication

An optional boolean to specify if this API requires authentication for all the methods

"authentication" : true

The default is false.

methods

A mandatory hash of method names and specifications. See "METHOD DESCRIPTION".

"methods" : { ... }

The methods hash MUST contain at least one method.

METHOD DESCRIPTION

A method must have a name, which is the key in the "methods" hash

"methods" : {
    "public_timeline" : { ... }
}

method

The mandatory method attribute specifies the HTTP method to use for this call

"method" : "GET"

path

The mandatory path attribute specifies the URI path for this method.

"path" : "/login"

The path can contain placeholders. A placeholder MUST begin with a <:>:

"path" : "/statuses/public_timeline.:format"

XXX How can non-placeholder :foo's be included in the path? i.e. is there an escape mechanism? XXX What happens in this example if 'format' isn't listed in params/required? XXX What happens if a parameter needs to be followed by a word character? i.e. can something like :{format}foo be used?

optional_params

An optional list of optional parameters (contrast with "required_params"). This list will be used to replace value in placeholders, and if not used in the path, will be added to the query part of the request URL.

"optional_params" : [
  "trim_user",
  "include_entities"
]

required_params

An optional list of required parameters (contrast with "optional_params"). This list will be used to replace value in placeholders and, if not used in the path, will be added to the query part of the request URL.

Parameters that are required MUST NOT be repeated in the optional_params field

"required" : [
  "format"
]

expected_status

An optional list of accepted HTTP status codes for this method

"expected" : [
  200,
  204
]

If expected is specified then an exception will be thrown if the response status is not in the list. If expected is not specified then an exception will be thrown if the response status is not in the range 200 through 299.

XXX a global default_expected could be handy.

description

An optional simple description for the method. This should not be considered as documentation.

"description" : "Returns the 20 most recent statuses, including retweets if they exist, from non-protected users"

authentication

An optional boolean to specify if this method requires authentication

"authentication" : false

base_url

An optional base URL for this method, if different to the default specified above.

base_url: http://api.twitter.com/1/

XXX might be nice to be able to express this as a relative URL (relative to api_base_url) That could be handled at build time.

formats

An optional list of supported formats

"format" : [
  "json",
  "xml"
]

documentation

Optional detailed documentation for the given method

"documentation" : "The public timeline is cached for 60 seconds. Requesting more frequently than that will not return any more data, and will count against your rate limit usage."

SAMPLE

A description for the twitter API (only the API description part and the first method):

{
    "base_url" : "http://api.twitter.com/1",
    "version" : "0.1",
    "methods" : {
        "public_timeline" : {
            "optional_params" : [
                "trim_user",
                "include_entities"
            ],
            "required_params" : [
                "format"
            ],
            "path" : "/statuses/public_timeline.:format",
            "method" : "GET"
        }
    }
}

CALLS

XXX

CHANGES

0.1 - 2010.10.xx

Initial version.

ACKNOWLEDGEMENTS

Some parts of this specification are adopted from the following specifications.

I'd like to thank authors of these great documents.

AUTHOR

franck cuny
nils grunwald

CONTRIBUTORS

damien "bl0b" leroux
François Perrad
Tim Bunce

COPYRIGHT AND LICENSE

Copyright XXX, 2010.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.