Skip to content

Instantly share code, notes, and snippets.

View marbemac's full-sized avatar

Marc MacLeod marbemac

View GitHub Profile
{
"name": "Retweet Stoplight's latest tweet",
"description": "This scenario will grab the latest Stoplight tweet, and retweet it. The twitter API requires that requests be authenticated with oauth1. Before you can run this scenario, you must fill out the variables below.\n\n1. Create a new app at [https://apps.twitter.com](https://apps.twitter.com). No callback url needed.\n2. Navigate to the keys and access tokens tab of your app (see screenshot), and copy paste the tokens and secrets below.\n3. Click run scenario above!\n\n![](http://i.imgur.com/I6Eg08M.png)",
"steps": [
{
"functions": [
{
"name": "Get latest tweet",
"input": {
"authorization": {
@marbemac
marbemac / swagger.json
Last active June 28, 2017 17:54
Stoplight To-do Demo Swagger
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "To-do Demo",
"description": "## Welcome\n\nThis is a place to put general notes and extra information, for internal use.\n\nTo get started designing/documenting this API, select a version on the left."
},
"host": "todos.stoplight.io",
"schemes": [
"http"
{
"swagger": "2.0",
"schemes": [
"http"
],
"basePath": "/api",
"host": "localhost:3000",
"info": {
"version": "",
@marbemac
marbemac / spec.json
Last active March 18, 2016 00:19
A barebones swagger example, that includes the StopLight extension to instruct Prism to validate and add a response header to all requests.
{
"swagger": "2.0",
"host": "myapi.com",
"schemes": ["http"],
"info": {},
"paths": {},
"definitions": {},
"x-stoplight": {
"beforeScript": "function(ctx, request) {}",
"afterScript": "function(ctx, request, response) { // messages contain any warnings or errors var messages = response.validate(); var isValid = response.valid.get(); // Set a header here, so that your testing tools can throw errors appropriately if (isValid) { response.header.set('Validation', 'Passed'); } else { response.header.set('Validation', 'Failed'); } }",
@marbemac
marbemac / config.json
Last active March 17, 2016 19:02
The default Prism config file.
{
"port": "4010",
"forwardHost": null,
"basePath": null,
"log": false,
"logLocation": "https://api.stoplight.io/v1",
"debug": true,
"mock": {
"enabled": false,
| files.readFile 3 ms (3)
| files.exists 1 ms (4)
| files.writeFileAtomically.....................................2,958 ms (2)
| ├─ files.writeFile 2,953 ms (2)
| └─ files.rename 5 ms (2)
| Rebuild App.................................................102,326 ms (1)
| ├─ compiler.compile(the app)....................................142 ms (1)
| │ └─ compileUnibuild (the app).................................142 ms (2)
| │ ├─ files.readdir 19 ms (126)
| │ ├─ files.stat 9 ms (813)
@marbemac
marbemac / main.js
Created September 8, 2015 06:25
Simple node server returning file
// Load the http module to create an http server.
var http = require('http');
var largeResponse = require('./large_response.json')
largeResponse = JSON.stringify(largeResponse)
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "application/json"});
@marbemac
marbemac / main.go
Created September 8, 2015 06:22
Simple go proxy, copying body
package main
import (
"bytes"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
@marbemac
marbemac / gist:27ee149aa5a50ce82823
Created July 12, 2015 18:08
Signals implementation
const runAction = (name, action, commonArgs, args) => {
console.log(`signals:${name}:${action.name}`, {action: action, commonArgs: commonArgs, args: args})
try {
return action(commonArgs, args)
} catch(e) {
console.error(`Error running ${action.name} action for the ${name} signal.`,
{action: action, err: e, commonArgs: commonArgs, args: args})
return Promise.reject(e)
}
@marbemac
marbemac / actions.js
Last active August 29, 2015 14:17
A query mixin for Baobab, supporting local and remote fetching, error handling, and loading handling.
// actions.js provides functions to fetch
// remote data and store it in the tree
// these remote functions should return
// promises
require('es6-promise').polyfill();
var stateTree = require('./stateTree'),
PostModel = require('./post'),
fetch = require('isomorphic-fetch'),