Skip to content

Instantly share code, notes, and snippets.

@netmilk
netmilk / apiary.apib
Created February 16, 2016 11:34
API Blueprint with MSON circular reference
# API Name
## Message Resource [/resource]
### Create a Message [POST]
+ Request
+ Attributes (Message)
+ Response 200
+ Attributes
+ id (string)
@netmilk
netmilk / dredd-php-travis.md
Last active December 22, 2015 00:05
Using Dredd, PHP and Travis CI

Using API Blueprint, Dredd, PHP and Travis CI

In case you don't have Node.js installed locally use NVM:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
$ nvm install v0.12.2
$ nvm use v0.12.2
$ nvm alias default v0.12.2
@netmilk
netmilk / hooks.js
Created December 21, 2015 22:52
Workaround Dredd hook for nullable type attributes in API Blueprint
var hooks = require('hooks');
// Recursively add null as acceptable type if there is string
// "#nullable" present in the property description
var patchPropertiesWithNullable = function(schema) {
if (typeof(schema['properties']) == 'object' && ! Array.isArray(schema['properties'])){
for (property in schema['properties']){
var partialSchemaToPatch = schema['properties'][property];
schema['properties'][property] = patchPropertiesWithNullable(partialSchemaToPatch);
};
@netmilk
netmilk / apiary.apib
Last active December 15, 2015 00:36
Workaround for nullable MSON attributes in Dredd Ruby and Node.js hooks
# My API
# My Resource [/my_resource]
# Its Action [GET]
+ Response 200 (application/json)
+ Attributes (My Structure)

23andme

{
	"name": "23AndMe",
    "desc": "23andMe is a personal genetics service. 23andMe offers individual genome and DNA testing and information. The 23andMe API allows developers to access and integrate the data from 23andMe with other applications and to create new applications. Individuals consent to giving third-party access to the 23andMe data. Some example API methods include accessing user information, retrieving profiles, and getting information on genotypes",
	"url": "https://api.23andme.com",
	"oauth2": {
		"authorize": "/authorize",
@netmilk
netmilk / lifesaving.apib
Created June 4, 2015 13:01
Example API with attributes
FORMAT: 1A
HOST: https://cryptic-badlands-8184.herokuapp.com/
# Life saving API
# Emergency [/912]
# Request first aid [POST]
+ Request (application/json)

Testing reveal agenda

  • Failing Dredd transactions programatically in hooks
  • Dredd hooks chai integration
  • Headers values are tested only for content-negotiation headers
  • Dredd documentation & tutorials kickoff
  • Writing Dredd hooks in Ruby
  • "Cloud Dredd" production API testing - proof of concept
  • Libpcap based HTTP interceptor (a.k.a SHAIN)
kolotoc:dredd-rack-sinatra-example netmilk$ bundle exec rake blueprint:verify 
Verify the API conformance against its blueprint.
dredd doc/*.apib doc/*.apib.md  --hookfiles doc/hooks/hooks-worker-client.coffee

info: Beginning Dredd testing...
info: Found Hookfiles: doc/hooks/hooks-worker-client.coffee
Spawning ruby worker
Dredd Ruby hooks worker is running

FORMAT: 1A

Httpbin API

GET /ip

  • Response 200 (application/json)

       {
         "origin": "89.22.64.131"
       }
    
@netmilk
netmilk / blueprint.md
Created February 13, 2015 15:42
Example for support of JSON schema draft v3 and v4 in Apiary

FORMAT: 1A

JSON Schema example API

API Exmample for demonstration of different versions of JSON schema

Valid schema v4 [/schema_v4_valid]

Create [POST]

  • Request (application/json)