zoran.antolovic@asynclabs.co
Zoran Antolovic
Idea / Approach / Concept
API - (RESTful) Web services
Open for suggestions and comments
joind.in/talk/945fc
when I start using a 3rd-party lib and notice there is no documentation
http://thecodinglove.com/post/49933241299
Exception in thread "main" com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException: Expected a boolean but was NUMBER
at line 1 column 59 path $.active
"How can I do something with something?"
I already told you, path is … - No, you didn’t.
Here is curl request example ... - How do I use that?
You really want to have some docs.
Shared document
Postman
API tests
...
I should teach my mobile developers to read and understand my API tests
I should teach my mobile developers to read and understand write API tests
Team leader’s facepalm.
For ultra-dumb ideas.
<?php
$I = new ApiTester($scenario);
$I->wantTo('create a user via API');
$I->amHttpAuthenticated('service_user', '123456');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('/users', ['name' => 'davert', 'email' => 'davert@codeception.com']);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":"ok"}');
Readable?
Have API docs that are easy to write, understand,
update and test.
Describe API behavior in a standardized way
Generate API docs
Automatically detect mistakes in API docs
JSON Schema - annotate and validate JSON documents.
JSON Hyper-schema - JSON Schema + links
http://json-schema.org
https://spacetelescope.github.io/understanding-json-schema/index.html
{
"title": "Web Camp Talk",
"type": "object",
"properties": {
"title": {
"type": "string",
"required": true
},
"speaker": {
"type": "string",
"required": true
},
"duration": {
"description": "Duration in min",
"type": "integer",
"enum": [25, 45]
}
}
}
{
"title": "Self-testable API docs",
"speaker": "Zoran Antolovic"
}
{
"title": "Self-testable API docs",
"speaker": "Zoran Antolovic",
"duration": 25
}
{
"title": "Self-testable API docs",
"speaker": "Zoran Antolovic",
"duration": 25,
"speakerEarsSize": "XXL"
}
open source > building from scratch
PRMD
https://github.com/interagent/prmd
JSON Schema HTML Documentation Generator
https://github.com/cloudflare/json-schema-docs-generator
Swagger
http://swagger.io
Open API Initiative (OAI)
https://openapis.org
RAML - RESTful API Modeling Language
http://raml.org
API Blueprint
https://apiblueprint.org
Design + Prototype + Document + Test
RAML - RESTful API Modeling Language
#%RAML 0.8
---
title: Jukebox API
baseUri: http://jukebox.api.com
version: v1
#%RAML 0.8
---
title: Jukebox API
baseUri: http://jukebox.api.com
version: v1
/songs
get
post
/{songId}
get
/file-content
get
post
/songs:
description: Collection of available songs in Jukebox
get:
description: Get a list of songs based on the song title.
queryParameters:
songTitle:
description: "The title of the song to search"
required: true
minLength: 3
type: string
example: "Nemoze Nam Niko Nista"
responses:
...
...
responses:
200:
body:
application/json:
example:
...
schema:
...
...
responses:
200:
body:
application/json:
example: |
{
"songId": "550e8400-e29b-41d4-a716-446655440000",
"songTitle": "Get Lucky"
}
schema:
...
responses:
200:
body:
application/json:
example:
...
schema: |
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required": true,
"properties": {
"songId": {
"type": "string",
"required": true,
"minLength": 36,
"maxLength": 36
},
"songTitle": {
"type": "string",
"required": true
}
}
...
Endpoints
Methods
Requests
Responses
iterate over defined endpoints
iterate over defined endpoint methods
construct request from example/schema
send request and get response
validate response against method response definition
happiness++
RAML testing tool
https://github.com/cybertk/abao
$ abao jukebox-api.raml
GET /songs -> 200
✓ Validate response code and body
POST /songs -> 200
✓ Validate response code only
GET /songs/{songId} -> 200
✓ Validate response code only
GET /songs/{songId} -> 404
✓ Validate response code only
GET /songs/{songId}/file-content -> 200
✓ Validate response code only
5 passing (15ms)
Missing support for multiple request/response models on the same endpoint based on headers or query params
Feedback pls joind.in/talk/945fc
www.asynclabs.co | www.itworkslocal.ly
zoran.antolovic@asynclabs.co
linkedin.com/in/antoloviczoran
twitter.com/zoran_antolovic