CARVIEW |
Select Language
HTTP/2 302
date: Sun, 20 Jul 2025 08:45:14 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://gist.github.com/indexzero/1039425
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
set-cookie: _gh_sess=lJSK0YCiciiC1pM1uXhAFsPnEOeb9FLl6IZ7s2QQnLV%2Fjl9CcznxZrbDoRqx1eYKdN3IKG%2F693nLJV7jYBij69LbVbji29NnRFQNoBIxRRnH9eE4icGU0lFjqul92zvcV14sqd46zuqUcIAzcxUVl6zfItf3ZGjFvnDBdnJZrTH0vymlK8T3Sd1u51tjZmsbxJFlTx6hqGeHCYjQPyBXHmXXYoypk6UBSAFrNuOS8y1x%2Flvi33%2FtEs%2FjUwGWo4NrG17wxrJfkBIdBIKFgiD8pw%3D%3D--qJd4WnlVQnCS0HEl--iMfugXbQ24iu7hBnmAgybw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.980862260.1753001114; Path=/; Domain=github.com; Expires=Mon, 20 Jul 2026 08:45:14 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Mon, 20 Jul 2026 08:45:14 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: D9E4:26CB0:EBB9E8:13657FF:687CAC9A
HTTP/2 200
date: Sun, 20 Jul 2025 08:45:14 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"9d48050e8d124ddb114ad035c5e160b5"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
x-github-request-id: D9E4:26CB0:EBBA02:1365829:687CAC9A
A quick sample of how to use api-easy with `npm test` · GitHub
Show Gist options
Save indexzero/1039425 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
June 22, 2011 03:05
-
Star
6
(6)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save indexzero/1039425 to your computer and use it in GitHub Desktop.
A quick sample of how to use api-easy with `npm test`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* helpers.js: Test macros for APIeasy. | |
* | |
* (C) 2011, Charlie Robbins | |
* | |
*/ | |
var assert = require('assert'), | |
http = require('http'), | |
journey = require('journey'); | |
var helpers = exports; | |
helpers.startServer = function (port) { | |
var token, router = new journey.Router({ | |
strict: false, | |
strictUrls: false, | |
api: 'basic' | |
}); | |
function isAuthorized (req, body, next) { | |
return parseInt(req.headers['x-test-authorized'], 10) === token ? next() : next(new journey.NotAuthorized()); | |
} | |
router.get('/tests').bind(function (res) { | |
res.send(200, {}, { ok: true }); | |
}); | |
router.post('/tests').bind(function (res, data) { | |
res.send(200, {}, data); | |
}); | |
router.post('/redirect').bind(function (res, data) { | |
res.send(302, { 'Location': 'https://localhost:8000/login' }, data); | |
}); | |
router.get('/login').bind(function (res) { | |
if (!token) { | |
token = Math.floor(Math.random() * 100); | |
} | |
res.send(200, {}, { token: token }); | |
}); | |
router.filter(isAuthorized, function () { | |
this.get('/restricted').bind(function (res) { | |
res.send(200, {}, { authorized: true }); | |
}); | |
}); | |
http.createServer(function (request, response) { | |
var body = ""; | |
request.addListener('data', function (chunk) { body += chunk }); | |
request.addListener('end', function () { | |
// | |
// Dispatch the request to the router | |
// | |
router.handle(request, body, function (result) { | |
response.writeHead(result.status, result.headers); | |
response.end(result.body); | |
}); | |
}); | |
}).listen(8000); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "api-easy-tests", | |
"description": "A quick sample of how to use api-easy with `npm test`", | |
"version": "0.1.0", | |
"author": "Charlie Robbins <charlie.robbins@gmail.com>", | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/indexzero/api-easy.git" | |
}, | |
"dependencies": { | |
"api-easy": "0.2.x" | |
}, | |
"devDependencies": { | |
"journey": ">= 0.4.0-pre-2" | |
}, | |
"scripts": { "test": "vows run-test.js --spec" }, | |
"engines": { "node": ">= 0.4.3" } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* core-test.js: Tests for core functionality of APIeasy. | |
* | |
* (C) 2011, Charlie Robbins | |
* | |
*/ | |
var vows = require('vows'), | |
assert = require('assert'), | |
APIeasy = require('api-easy'), | |
helpers = require('./helpers'); | |
var scopes = ['When using the Test API', 'the Test Resource']; | |
helpers.startServer(8000); | |
var suite = APIeasy.describe('api/test'); | |
scopes.forEach(function (text) { | |
suite.discuss(text); | |
}); | |
suite.use('localhost', 8000) | |
.setHeader('Content-Type', 'application/json') | |
.followRedirect(false) | |
.get('/tests') | |
.expect(200, { ok: true }) | |
.post('/tests', { dynamic: true }) | |
.expect(200, { dynamic: true }) | |
.post('/redirect', { dynamic: true }) | |
.expect(302, { dynamic: true }) | |
.get('/login') | |
.expect(200) | |
.expect('should respond with the authorize token', function (err, res, body) { | |
var result = JSON.parse(body); | |
assert.isNotNull(result.token); | |
suite.before('setAuth', function (outgoing) { | |
outgoing.headers['x-test-authorized'] = result.token; | |
return outgoing; | |
}); | |
}) | |
.next() | |
.get('/restricted') | |
.expect(200, { authorized: true }) | |
.export(module); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -o api-easy-tests.tar.gz https://gist.github.com/gists/1039425/download | |
tar -xvf api-easy-tests.tar.gz | |
cd gist1039425* | |
npm install | |
npm test |
helpers.js:14
There is a little error. You pass port, but start server on hardcoded 8000.
@silverbucket
npm install vows not just globally, but also in the directory of the gist. did work for me.
P.S. api-easy is awesome. will use it in my project. (Small geotracking API)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
I've been unable to get this to work, when I use the usage.sh I get an error about cannot find module 'vows', then if i install that module I get an error about not finding 'helpers' but I'm not sure what to do in that case.