Skip to content

Instantly share code, notes, and snippets.

$ npm install -g curl-trace-parser
$ brew install --HEAD \
https://raw.github.com/apiaryio/snowcrash/master/tools/homebrew/snowcrash.rb
$ curl --trace - --header "Content-Type: application/json" \
--request POST \
--data-binary "{ \"product\":\"1AB23ORM\", \"quantity\": 2 }" \
"http://curltraceparser.apiary.io/shopping-cart" \
| curl-trace-parser --blueprint \
| snowcrash
name:
@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 / 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 / .travis.yml
Last active December 23, 2015 12:49
Travis dotfile for testing with DREDD
language: node_js
node_js:
- 0.8
- 0.10
before_install:
- npm install -g dredd
script: ./scripts/test
notifications:
email:
recipients:
@netmilk
netmilk / test
Created September 20, 2013 13:22
Script for testing Express.js backend API application written in Coffee with Dredd
#!/bin/sh
./node_modules/coffee-script/bin/coffee app.coffee &
sleep 1
PID=$!
dredd apiary.apib http://localhost:3000/
RESULT=$?
kill -9 $PID
exit $RESULT

FORMAT: X-1A

URI Parameters API

This API demonstrates & tests various URI parameter description.

PUT /1/{id}

  • Parameters

    • id ... id of a post
  • Response 204

@netmilk
netmilk / test
Created October 8, 2013 13:52
Shell script to run express app on background, run API test and, kill app and return exit status from the test runnure
#!/bin/sh
./node_modules/coffee-script/bin/coffee app.coffee &
sleep 5
PID=$!
dredd apiary.apib http://localhost:3000/
RESULT=$?
kill -9 $PID
exit $RESULT
@netmilk
netmilk / .travis.yml
Created October 8, 2013 14:02
Example Travis CI dotfile for testing APIs with Dredd
language: node_js
node_js:
- 0.8
- 0.10
before_install:
- npm install -g dredd
script: ./scripts/test
services:
- mongodb
before_script:
kolotoc:~ netmilk$ git clone git://github.com/apiaryio/snowcrash.git
Cloning into 'snowcrash'...
remote: Counting objects: 2090, done.
remote: Compressing objects: 100% (702/702), done.
remote: Total 2090 (delta 1434), reused 1965 (delta 1311)
Receiving objects: 100% (2090/2090), 951.94 KiB | 700.00 KiB/s, done.
Resolving deltas: 100% (1434/1434), done.
Checking connectivity... done
kolotoc:~ netmilk$ cd snowcrash
kolotoc:snowcrash netmilk$ git submodule update --init --recursive

My API

Fish [/fish]

Catch [GET]

  • Response 404

    Whip!