Skip to content

Commit f319e07

Browse files
committed
Client docs
1 parent c21994e commit f319e07

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ REST framework requires the following:
9191

9292
The following packages are optional:
9393

94-
* [coreapi][coreapi] (1.21.0+) - Schema generation support.
94+
* [coreapi][coreapi] (1.31.0+) - Schema generation support.
9595
* [Markdown][markdown] (2.1.0+) - Markdown support for the browsable API.
9696
* [django-filter][django-filter] (0.9.2+) - Filtering support.
9797
* [django-crispy-forms][django-crispy-forms] - Improved HTML display for filtering.

docs/topics/api-clients.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,38 +139,51 @@ that credentials are not leaked across differing APIs.
139139

140140
The format for adding a new credential is:
141141

142-
coreapi credentials add <domain> <credentials string>
142+
$ coreapi credentials add <domain> <credentials string>
143143

144144
For instance:
145145

146-
coreapi credentials add api.example.org "Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
146+
$ coreapi credentials add api.example.org "Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
147147

148148
The optional `--auth` flag also allows you to add specific types of authentication,
149149
handling the encoding for you. Currently only `"basic"` is supported as an option here.
150150
For example:
151151

152-
coreapi credentials add api.example.org tomchristie:foobar --auth basic
152+
$ coreapi credentials add api.example.org tomchristie:foobar --auth basic
153153

154154
You can also add specific request headers, using the `headers` command:
155155

156-
coreapi headers add api.example.org x-api-version 2
156+
$ coreapi headers add api.example.org x-api-version 2
157157

158158
For more information and a listing of the available subcommands use `coreapi
159159
credentials --help` or `coreapi headers --help`.
160160

161+
## Codecs
162+
163+
By default the command line client only includes support for reading Core JSON
164+
schemas, however it for installing additional codecs.
165+
166+
$ pip install openapi-codec jsonhyperschema-codec hal-codec
167+
$ coreapi codecs show
168+
Codecs
169+
corejson "application/vnd.coreapi+json"
170+
openapi "application/openapi+json"
171+
jsonhyperschema "application/schema+json"
172+
hal "application/hal+json"
173+
161174
## Utilities
162175

163176
The command line client includes functionality for bookmarking API URLs
164177
under a memorable name. For example, you can add a bookmark for the
165178
existing API, like so...
166179

167-
coreapi bookmarks add accountmanagement
180+
$ coreapi bookmarks add accountmanagement
168181

169182
There is also functionality for navigating forward or backward through the
170183
history of which API URLs have been accessed.
171184

172-
coreapi history show
173-
coreapi history back
185+
$ coreapi history show
186+
$ coreapi history back
174187

175188
For more information and a listing of the available subcommands use
176189
`coreapi bookmarks --help` or `coreapi history --help`.
@@ -179,20 +192,20 @@ For more information and a listing of the available subcommands use
179192

180193
To display the current `Document`:
181194

182-
coreapi show
195+
$ coreapi show
183196

184197
To reload the current `Document` from the network:
185198

186-
coreapi reload
199+
$ coreapi reload
187200

188201
To load a schema file from disk:
189202

190-
coreapi load my-api-schema.json --format corejson
203+
$ coreapi load my-api-schema.json --format corejson
191204

192205
To remove the current document, along with all currently saved history,
193206
credentials, headers and bookmarks:
194207

195-
coreapi clear
208+
$ coreapi clear
196209

197210
---
198211

@@ -206,7 +219,7 @@ API that exposes a supported schema format.
206219
You'll need to install the `coreapi` package using `pip` before you can get
207220
started.
208221

209-
pip install coreapi
222+
$ pip install coreapi
210223

211224
In order to start working with an API, we first need a `Client` instance. The
212225
client holds any configuration around which codecs and transports are supported
@@ -263,14 +276,15 @@ and subsequently to receive JSON responses made against the API.
263276
You can use a codec directly, in order to load an existing schema definition,
264277
and return the resulting `Document`.
265278

266-
schema_definition = open('my-api-schema.json', 'r').read()
279+
input_file = open('my-api-schema.json', 'rb')
280+
schema_definition = input_file.read()
267281
codec = codecs.CoreJSONCodec()
268282
schema = codec.load(schema_definition)
269283

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

272286
schema_definition = codec.dump(schema)
273-
output_file = open('my-api-schema.json', 'r')
287+
output_file = open('my-api-schema.json', 'rb')
274288
output_file.write(schema_definition)
275289

276290
## Transports

0 commit comments

Comments
 (0)