Skip to content

Commit f3ed693

Browse files
Bartleby2718lovelydinosaur
authored andcommitted
Add missing punctuation marks and URL name (#7108)
- trailing commas (as both Python and JavaScript allow them) - trailing semicolons in JavaScript - URL name `api-docs`
1 parent 62ae241 commit f3ed693

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

docs/topics/api-clients.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ First, install the API documentation views. These will include the schema resour
384384

385385
urlpatterns = [
386386
...
387-
url(r'^docs/', include_docs_urls(title='My API service'))
387+
url(r'^docs/', include_docs_urls(title='My API service'), name='api-docs'),
388388
]
389389

390390
Once the API documentation URLs are installed, you'll be able to include both the required JavaScript resources. Note that the ordering of these two lines is important, as the schema loading requires CoreAPI to already be installed.
@@ -401,14 +401,14 @@ Once the API documentation URLs are installed, you'll be able to include both th
401401

402402
The `coreapi` library, and the `schema` object will now both be available on the `window` instance.
403403

404-
const coreapi = window.coreapi
405-
const schema = window.schema
404+
const coreapi = window.coreapi;
405+
const schema = window.schema;
406406

407407
## Instantiating a client
408408

409409
In order to interact with the API you'll need a client instance.
410410

411-
var client = new coreapi.Client()
411+
var client = new coreapi.Client();
412412

413413
Typically you'll also want to provide some authentication credentials when
414414
instantiating the client.
@@ -421,9 +421,9 @@ the user to login, and then instantiate a client using session authentication:
421421

422422
let auth = new coreapi.auth.SessionAuthentication({
423423
csrfCookieName: 'csrftoken',
424-
csrfHeaderName: 'X-CSRFToken'
425-
})
426-
let client = new coreapi.Client({auth: auth})
424+
csrfHeaderName: 'X-CSRFToken',
425+
});
426+
let client = new coreapi.Client({auth: auth});
427427

428428
The authentication scheme will handle including a CSRF header in any outgoing
429429
requests for unsafe HTTP methods.
@@ -434,10 +434,10 @@ The `TokenAuthentication` class can be used to support REST framework's built-in
434434
`TokenAuthentication`, as well as OAuth and JWT schemes.
435435

436436
let auth = new coreapi.auth.TokenAuthentication({
437-
scheme: 'JWT'
438-
token: '<token>'
439-
})
440-
let client = new coreapi.Client({auth: auth})
437+
scheme: 'JWT',
438+
token: '<token>',
439+
});
440+
let client = new coreapi.Client({auth: auth});
441441

442442
When using TokenAuthentication you'll probably need to implement a login flow
443443
using the CoreAPI client.
@@ -448,20 +448,20 @@ request to an "obtain token" endpoint
448448
For example, using the "Django REST framework JWT" package
449449

450450
// Setup some globally accessible state
451-
window.client = new coreapi.Client()
452-
window.loggedIn = false
451+
window.client = new coreapi.Client();
452+
window.loggedIn = false;
453453

454454
function loginUser(username, password) {
455-
let action = ["api-token-auth", "obtain-token"]
456-
let params = {username: "example", email: "[email protected]"}
455+
let action = ["api-token-auth", "obtain-token"];
456+
let params = {username: "example", email: "[email protected]"};
457457
client.action(schema, action, params).then(function(result) {
458458
// On success, instantiate an authenticated client.
459459
let auth = window.coreapi.auth.TokenAuthentication({
460460
scheme: 'JWT',
461-
token: result['token']
461+
token: result['token'],
462462
})
463-
window.client = coreapi.Client({auth: auth})
464-
window.loggedIn = true
463+
window.client = coreapi.Client({auth: auth});
464+
window.loggedIn = true;
465465
}).catch(function (error) {
466466
// Handle error case where eg. user provides incorrect credentials.
467467
})
@@ -473,23 +473,23 @@ The `BasicAuthentication` class can be used to support HTTP Basic Authentication
473473

474474
let auth = new coreapi.auth.BasicAuthentication({
475475
username: '<username>',
476-
password: '<password>'
476+
password: '<password>',
477477
})
478-
let client = new coreapi.Client({auth: auth})
478+
let client = new coreapi.Client({auth: auth});
479479

480480
## Using the client
481481

482482
Making requests:
483483

484-
let action = ["users", "list"]
484+
let action = ["users", "list"];
485485
client.action(schema, action).then(function(result) {
486486
// Return value is in 'result'
487487
})
488488

489489
Including parameters:
490490

491-
let action = ["users", "create"]
492-
let params = {username: "example", email: "[email protected]"}
491+
let action = ["users", "create"];
492+
let params = {username: "example", email: "[email protected]"};
493493
client.action(schema, action, params).then(function(result) {
494494
// Return value is in 'result'
495495
})
@@ -512,12 +512,12 @@ The coreapi package is available on NPM.
512512

513513
You'll either want to include the API schema in your codebase directly, by copying it from the `schema.js` resource, or else load the schema asynchronously. For example:
514514

515-
let client = new coreapi.Client()
516-
let schema = null
515+
let client = new coreapi.Client();
516+
let schema = null;
517517
client.get("https://api.example.org/").then(function(data) {
518518
// Load a CoreJSON API schema.
519-
schema = data
520-
console.log('schema loaded')
519+
schema = data;
520+
console.log('schema loaded');
521521
})
522522

523523
[heroku-api]: https://devcenter.heroku.com/categories/platform-api

0 commit comments

Comments
 (0)