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

Define a single format (or specific formats) #178

Closed
amrnt opened this issue May 29, 2012 · 6 comments
Closed

Define a single format (or specific formats) #178

amrnt opened this issue May 29, 2012 · 6 comments

Comments

@amrnt
Copy link

amrnt commented May 29, 2012

What if I want to access only JSON? I dont want XML to be available or whatever!

@dblock
Copy link
Member

dblock commented May 30, 2012

Make sure to have format :json. We might also need to weed out XML and TXT, I am not sure you can remove those by default - add to this issue anything unexpected that you're seeing after that.

@dpehrson
Copy link

Just wanted to pop in here and second this, specifically because it appears XML serialization is borked when responding with an entity, it just shows .to_s of the entity class and doesn't serialize it.

@marcusg
Copy link
Contributor

marcusg commented Dec 11, 2012

+1

I need only json-support and don't know how to disable xml and txt formatting...

@marcusg
Copy link
Contributor

marcusg commented Dec 14, 2012

as a workaround i'll validate the request in a before_filter like:

      def validate_request!
        request.env["api.format"] = :json # force api to use json!
        respond_with_404! unless ["json", nil].include? params.format # only respond to json
      end

@dblock
Copy link
Member

dblock commented Dec 16, 2012

I've committed 733f7df which resets default content types when you call content_type. This makes it so as soon as you start defining your own content-types, the default ones are removed.

JSON-only API (everything else returns 406)

format :json
content_type :json, "application/json"

Both JSON and XML, default JSON.

format :json
content_type :json, "application/json"
content_type :xml, "application/xml"

@dblock dblock closed this as completed Dec 16, 2012
@amrnt
Copy link
Author

amrnt commented Dec 16, 2012

👌

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