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

How to get JSON body as a params in action? #118

Closed
nilcolor opened this issue Aug 14, 2015 · 6 comments
Closed

How to get JSON body as a params in action? #118

nilcolor opened this issue Aug 14, 2015 · 6 comments

Comments

@nilcolor
Copy link

I've create really simple Lotus app (https://gist.github.com/nilcolor/21ead88d1517e824f103). And I'd like to receive JSON data (via POST's body). But... controller receives request, responds with OK but params are empty... (not really empty - it's full Rack params hash but without data I need).
If params are posted in URL - they are readable via params arg. Even if action is accept :json btw

@runlevel5
Copy link
Member

assigned to @brennovich

@carloslopes
Copy link

Some things appeared when @brennovich and I were investings this.

Probably @nilcolor didn't configure the body_parsers of his app. If he configure the body_parsers for json the params passed to the action will start to be available.

But some things aren't clear, and maybe @joneslee85 can help us to figure them out.

  • The purpose of body_parsers configuration is: Define different parsers that will be used when a request is received on specific MIME types
  • The purpose of accept is: block requests that aren't on the defined MIME types

Are this assumptions right?

ps: accept is currently not doing what it should, because if we configure a controller to accept only json requests, it doesn't return status code 406 for requests with different content-types

@brennovich
Copy link

Yep, as @carloslopes said @nilcolor, please make sure to uncomment this option in your application.rb:

screen shot 2015-08-25 at 11 29 15 pm

Once you get this done you'll start to get your params :)

@carloslopes
Copy link

Issue related to the accept problem: #123

@nilcolor
Copy link
Author

@brennovich @carloslopes - thank you.

@runlevel5
Copy link
Member

Thanks all for helping me out, this community is uber! I close this ticket now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants