Skip to content

Instantly share code, notes, and snippets.

@nicosommi
Last active August 29, 2015 14:20
Show Gist options
  • Save nicosommi/8bea1437f615c0c64163 to your computer and use it in GitHub Desktop.
Save nicosommi/8bea1437f615c0c64163 to your computer and use it in GitHub Desktop.
unirest 0.4.0 custom media type issue
"use strict";
var express = require("express");
var bodyParser = require("body-parser");
var unirest = require("unirest");
require("should");
var app = express();
var host, port, url;
var responseData = {message: "some message under a json object"};
describe("unirest", function unirestDescribe () {
beforeEach(function(done) {
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
app.get("/", function handleRoot(req, res) {
res.set("content-type", "application/vnd.api+json");
res.send(responseData);
});
var server = app.listen(3000, function liftServer () {
host = server.address().address;
port = server.address().port;
//url = `http://${host}:${port}`;
url = "http://localhost:3000";
console.log("Example app listening at http://%s:%s", host, port);
done();
});
});
it("should get a json from the main route", function jsonTest (done) {
unirest
.get(url)
.type("json")
.end(function endJsonTest(response) {
response.body.should.eql(responseData);
done();
});
});
});
{
"name": "unirest-cmt-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha index.js"
},
"author": "nicosommi",
"license": "MIT",
"dependencies": {
"body-parser": "^1.12.3",
"express": "^4.12.3",
"mocha": "^2.2.4",
"should": "^6.0.1",
"unirest": "^0.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment