Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request without Content-Type application/json have empty body #40

Closed
Glavin001 opened this issue Feb 17, 2014 · 4 comments · Fixed by #52
Closed

Request without Content-Type application/json have empty body #40

Glavin001 opened this issue Feb 17, 2014 · 4 comments · Fixed by #52
Labels
Milestone

Comments

@Glavin001
Copy link
Contributor

Request without Content-Type application/json have empty body.

I am using Postman REST Client and neglected to set the Content-Type to application/json which resulted in the body not being parsed by express.json and it was passing data = {} into my services' create handler.

I suggest that, since JSON is the notation being used for serialization with Feathers, that if the Content-Type is blank, it should default to application/json.

@Glavin001
Copy link
Contributor Author

See http://stackoverflow.com/a/17228529/2578205 for solution implementation.

@daffl
Copy link
Member

daffl commented Feb 20, 2014

So technically you could add your own responder using res.format with app.configure(feathers.rest({ responder: function(req, res, next) })). I think the text formatter is the default one (which should also work for empty content types). The problem is, that it is already preconfigured since REST is initialized by default. I don't think we should turn that default behaviour off. Maybe allow to change it by setting app.rest.responder?

@daffl
Copy link
Member

daffl commented Apr 8, 2014

#52 should fix it by allowing to set up the REST provider later. This is the test I added to test it:

it('Lets you configure your own middleware before the handler (#40)', function(done) {
    var data = { description: 'Do dishes!', id: 'dishes' };
    var app = feathers({ rest: false });

    app.use(function defaultContentTypeMiddleware (req, res, next) {
      req.headers['content-type'] = req.headers['content-type'] || 'application/json';
      next();
    })
    .use(feathers.urlencoded())
    .use(feathers.json())
    .configure(feathers.rest())
    .use('/todo', {
      create: function (data, params, callback) {
        callback(null, data);
      }
    });

    var server = app.listen(4775);
    request({
      method: 'POST',
      url: 'http://localhost:4775/todo',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(data)
    }, function (error, response, body) {
      assert.deepEqual(JSON.parse(body), data);
      server.close(done);
    });
  });

@daffl daffl closed this as completed in #52 Apr 8, 2014
mlaug added a commit to mlaug/feathers that referenced this issue Apr 16, 2014
* 'master' of github.com:feathersjs/feathers:
  release 0.4.0
  Updating readme with 0.4.0 changelog.
  Allow to configure REST handler manually (feathersjs#40)
  Implementing event filtering and default params for Primus. Extracted common Socket functionality.
  Documentation for service event dispatching and some cleanup.
  Adding event dispatching tests for SocketIO.
  Adding SocketIO handshake data to service call parameters.
  Initial implementation for SocketIO dispatching mechanism.
  release 0.3.2
  Changelog for 0.3.2
  Changing dependencies versions back so that they work with older Node versions.
  Upgrading dependencies and switching to Lodash.
  refactor feathers use
  feathers use other feathers apps
daffl added a commit that referenced this issue Aug 19, 2018
daffl added a commit that referenced this issue Aug 21, 2018
daffl added a commit that referenced this issue Aug 25, 2018
* Update plugin infrastructure to use shx

* Fix linting error
daffl added a commit that referenced this issue Aug 28, 2018
daffl pushed a commit that referenced this issue Aug 29, 2018
* chore(package): update dependencies

https://greenkeeper.io/

* docs(readme): add Greenkeeper badge

https://greenkeeper.io/

* Update to latest Semistandard
daffl added a commit that referenced this issue Aug 29, 2018
daffl pushed a commit that referenced this issue Aug 29, 2018
* chore(package): update dependencies

https://greenkeeper.io/

* docs(readme): add Greenkeeper badge

https://greenkeeper.io/

* Update to latest Semistandard
@lock
Copy link

lock bot commented Feb 8, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants