Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc836aa
Initial pass at schema support
lovelydinosaur Jun 8, 2016
b64340b
Add coreapi to optional requirements.
lovelydinosaur Jun 9, 2016
c890ad4
Clean up test failures
lovelydinosaur Jun 9, 2016
2d28390
Add missing newline
lovelydinosaur Jun 9, 2016
744dba4
Minor docs update
lovelydinosaur Jun 9, 2016
56ece73
Version bump for coreapi in requirements
lovelydinosaur Jun 9, 2016
99adbf1
Catch SyntaxError when importing coreapi with python 3.2
lovelydinosaur Jun 9, 2016
80c595e
Add --diff to isort
lovelydinosaur Jun 9, 2016
47c7765
Import coreapi from compat
lovelydinosaur Jun 9, 2016
29e228d
Fail gracefully if attempting to use schemas without coreapi being in…
lovelydinosaur Jun 9, 2016
eeffca4
Tutorial updates
lovelydinosaur Jun 9, 2016
6c60f58
Docs update
lovelydinosaur Jun 9, 2016
b7fcdd2
Initial schema generation & first tutorial 7 draft
lovelydinosaur Jun 10, 2016
2e60f41
Spelling
lovelydinosaur Jun 10, 2016
2ffa145
Remove unused variable
lovelydinosaur Jun 10, 2016
b709dd4
Docs tweak
lovelydinosaur Jun 10, 2016
474a23e
Merge branch 'master' into schema-support
lovelydinosaur Jun 14, 2016
4822896
Added SchemaGenerator class
lovelydinosaur Jun 15, 2016
1f76cca
Fail gracefully if coreapi is not installed and SchemaGenerator is used
lovelydinosaur Jun 15, 2016
cad24b1
Schema docs, pagination controls, filter controls
lovelydinosaur Jun 21, 2016
8fb2602
Resolve NameError
lovelydinosaur Jun 21, 2016
b438281
Add 'view' argument to 'get_fields()'
lovelydinosaur Jun 21, 2016
8519b4e
Remove extranous blank line
lovelydinosaur Jun 21, 2016
2f5c974
Add integration tests for schema generation
lovelydinosaur Jun 22, 2016
e78753d
Only set 'encoding' if a 'form' or 'body' field exists
lovelydinosaur Jun 22, 2016
84bb5ea
Do not use schmea in tests if coreapi is not installed
lovelydinosaur Jun 24, 2016
63e8467
Inital pass at API client docs
lovelydinosaur Jun 29, 2016
bdbcb33
Inital pass at API client docs
lovelydinosaur Jun 29, 2016
7236af3
More work towards client documentation
lovelydinosaur Jun 30, 2016
89540ab
Add coreapi to optional packages list
lovelydinosaur Jul 4, 2016
e3ced75
Clean up API clients docs
lovelydinosaur Jul 4, 2016
12be5b3
Resolve typo
lovelydinosaur Jul 4, 2016
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
Prev Previous commit
Next Next commit
More work towards client documentation
  • Loading branch information
lovelydinosaur committed Jun 30, 2016
commit 7236af32f8993abb642cf36f0e9b1dd4facbeb53
87 changes: 76 additions & 11 deletions docs/topics/api-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ To install the Core API command line client, use pip.

pip install coreapi

**TODO**
To start inspecting and interacting with an API the schema must be loaded.

coreapi get http://api.example.org/

This will then load the schema, displaying the resulting `Document`. This
`Document` includes all the available interactions that may be made against the API.

To interact with the API, use the `action` command. This command requires a list
of keys that are used to index into the link.

Expand Down Expand Up @@ -130,21 +133,20 @@ For more information and a listing of the available subcommands use

## Other commands

**TODO**

To display the current `Document`, use the `show` command.
To display the current `Document`:

coreapi show

To reload the current `Document` from the network, use `reload`.
To reload the current `Document` from the network:

coreapi reload

To load a schema file from disk.
To load a schema file from disk:

load
coreapi load my-api-schema.json --format corejson

To remove the current document, history, credentials, headers and bookmarks, use `clear`:
To remove the current document, along with all currently saved history,
credentials, headers and bookmarks:

coreapi clear

Expand All @@ -157,12 +159,75 @@ API that exposes a supported schema format.

## Getting started

You'll need to install the `coreapi` package using `pip` before you can get
started. Once you've done so, open up a python terminal.

In order to start working with an API, we first need a `Client` instance. The
client holds any configuration around which codecs and transports are supported
when interacting with an API, which allows you to provide for more advanced
kinds of behaviour.

import coreapi
client = coreapi.Client()
schema = client.get('http://...')

client.action(schema, ['users', 'list'])
client.action(schema, ['users', 'list'], params={"page": 2})
Once we have a `Client` instance, we can fetch an API schema from the network.

schema = client.get('https://api.example.org/')

The object returned from this call will be a `Document` instance, which is
the internal representation of the interface that we are interacting with.

Now that we have our schema `Document`, we can now start to interact with the API:

users = client.action(schema, ['users', 'list'])

Some endpoints may include named parameters, which might be either optional or required:

new_user = client.action(schema, ['users', 'create'], params={"username": "max"})

**TODO**: *file uploads*, *describe/help?*

## Codecs

Codecs are responsible for encoding or decoding Documents.

The decoding process is used by a client to take a bytestring of an API schema
definition, and returning the Core API `Document` that represents that interface.

A codec should be associated with a particular media type, such as **TODO**.

This media type is used by the server in the response `Content-Type` header,
in order to indicate what kind of data is being returned in the response.

#### Configuring codecs

**TODO**

#### Loading and saving schemas

You can use a codec directly, in order to load an existing schema definition,
and return the resulting `Document`.

schema_definition = open('my-api-schema.json', 'r').read()
codec = codecs.CoreJSONCodec()
schema = codec.load(schema_definition)

You can also use a codec directly to generate a schema definition given a `Document` instance:

schema_definition = codec.dump(schema)
output_file = open('my-api-schema.json', 'r')
output_file.write(schema_definition)

#### Writing custom codecs

## Transports

**TODO**

#### Configuring transports

**TODO**

#### Writing custom transports

**TODO**