Comments (6)
This seems to work if you load Rack::PostBodyContentTypeParser from rack-contrib. Seems like something important to support
from grape.
Perhaps add a documentation patch to show how to include it?
from grape.
I've noticed this as well when sending POST requests from Safari, but everything works from Chrome. The only difference we can find is that the request content type header is set to "application/json; chartset=UTF-8" but in Chrome it's just "application/json". Going to fork and write a spec to see if this is actually the issue. Will post back results here.
from grape.
Why was this issue closed? I can't find any information about how to achieve posting JSON propertly to the Grape API
See this comment for more information
from grape.
I'm surprised this hasn't been addressed/fixed yet.
Here's how I hacked it in an old project:
# Overload grape to parse application/json objects until this is fixed
module Grape
class API
class << self
def call(env)
case env['CONTENT_TYPE']
when /^application\/json/
env.update('rack.request.form_hash' => JSON.parse(env['rack.input'].read), 'rack.request.form_input' => env['rack.input'])
end
logger.info "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
route_set.freeze.call(env)
end
end
end
end
from grape.
@aaronchi thanks a bunch for that. So much cleaner than what I am doing now for every put or post.
I had to change a tiny thing the code provided by @aaronchi doesn't work for get and delete requests
# Overload grape to parse application/json objects until this is fixed
module Grape
class API
class << self
def call(env)
case env['CONTENT_TYPE']
when /^application\/json/
hash = env['rack.input'].read
parsedForm = JSON.parse(hash) unless hash.blank?
env.update('rack.request.form_hash' => parsedForm, 'rack.request.form_input' => env['rack.input']) if parsedForm
end
logger.info "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
route_set.freeze.call(env)
end
end
end
end
Having to go through this makes me sick. But works for now, something like this should probably be implemented in the head branch but I am unsure about what to test for etc. Some guidance would be nice.
from grape.
Related Issues (20)
- Allow to define the API version where a endpoint is available HOT 3
- Param with multiple acceptable Hash Types HOT 4
- Define contract instead of params HOT 8
- undefined method `rewind' for #<Rack::Lint::Wrapper::InputWrapper w/Rack >= 3.0 HOT 4
- custom type not suppot multiple types, raise `Grape::Exceptions::ValidationErrors` HOT 1
- Route#options and Route#settings are confusing HOT 1
- Ruby 3.3 && cookiejar = ArgumentError HOT 1
- Use Rack's HeadersHash instead of {}
- endpoint method_missing vs override inspect HOT 2
- Values Validator => Proc's arity < 2 ? HOT 3
- Rails Edge requires Ruby >= 3.1
- Fix specs for Rack Edge
- Fix `params` warning method redefined
- Better tracking of gems deprecation
- Rack::Lint::Error => a header value must be a String or Array of Strings, but the value of 'content-type' is a NilClass HOT 2
- Recognize_path should account for HTTP method HOT 1
- Grape and Protecting Against Mass Assignment Abuse HOT 2
- Why do you convert PATH_INFO? Is there some RFC? HOT 2
- Add support for exclusive parameter groups (e.g. exactly_one_of) HOT 2
- Drop support rack ~> 1 ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grape.