Skip to content

Commit

Permalink
Merge pull request #419 from l2es/HAL
Browse files Browse the repository at this point in the history
Add application/hal+json content-type support
  • Loading branch information
tomas authored Dec 8, 2023
2 parents d3ec179 + 4b6503e commit 3aaf142
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,14 @@ To run the tests with debug logs, set the environment variable `NODE_DEBUG` to `

> Note: Tests currently only work on linux-based environments that have `/proc/self/fd`. They *do not* work on MacOS environments.
> You can use Docker to run tests by creating a container and mounting the needle project directory on `/app`
> `docker create --name Needle -v $(pwd) -w /app -v $(pwd)/node_modules -i node:argon`
docker create --name Needle -v $(pwd) -w /app -v $(pwd)/node_modules -i node:argon

Or alternatively:

docker run -it -w /app --name Needle \
--mount type=bind,source="$(pwd)",target=/app \
node:fermium bash

Credits
-------
Expand Down
1 change: 1 addition & 0 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function buildParser(name, types, fn) {

buildParser('json', [
'application/json',
'application/hal+json',
'text/javascript',
'application/vnd.api+json'
], function(buffer, cb) {
Expand Down
41 changes: 41 additions & 0 deletions test/parsing_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,45 @@ describe('parsing', function(){

});

describe('when response is a HAL JSON content-type', function () {

var json_string = '{"name": "Tomás", "_links": {"href": "https://github.com/tomas/needle.git"}}';

before(function(done){
server = http.createServer(function(req, res) {
res.setHeader('Content-Type', 'application/hal+json');
res.end(json_string);
}).listen(port, done);
});

after(function(done){
server.close(done);
});

describe('and parse option is not passed', function() {

describe('with default parse_response', function() {

before(function() {
needle.defaults().parse_response.should.eql('all')
})

it('should return object', function(done){
needle.get('localhost:' + port, function(err, response, body){
should.ifError(err);
body.should.deepEqual({
'name': 'Tomás',
'_links': {
'href': 'https://github.com/tomas/needle.git'
}});
done();
});
});

});

})

});

})

0 comments on commit 3aaf142

Please sign in to comment.