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

Accept request header for json #161

Closed
bigardone opened this issue Mar 5, 2015 · 6 comments
Closed

Accept request header for json #161

bigardone opened this issue Mar 5, 2015 · 6 comments
Milestone

Comments

@bigardone
Copy link
Contributor

Hi!
I'm using Marty in a Rails application and I have noticed that all requests done by my HttpStores are done as *"* / " instead of being "application/json" which is the format that I need. To do so using jquery for example I can set the dataType: 'json' attribute and I was wondering if something similar could be done in Marty.

This is what request format looks like using jquery ajax:

<Mime::Type:0x007f8d74b18240 @synonyms=["text/x-json", "application/jsonrequest"], @symbol=:json, @string="application/json">

And this is using Marty's HttpStore:

<Mime::Type:0x007f8d789191c0 @synonyms=[], @symbol=nil, @string="*/*">

Thanks in advance and thanks also for the awesome work you're doing here :)

@jhollingworth
Copy link
Contributor

could you give me an example of how you're making the http request? If you pass in an object for the body then Marty should automatically add the application/json header.

@bigardone
Copy link
Contributor Author

This is how I do it:

CollectionsAPI = Marty.createStateSource
  type: 'http'

  findAll: ->
    @get(Routes.collections_path()).then (res)->
      CollectionsSourceActionCreators.receiveItems res.body

@jhollingworth
Copy link
Contributor

ah, I see. yeah dataType: 'json' would be really helpful here. I will add it to v0.9 (hopefully will be out in a week or two). In the meantime you will have do to

CollectionsAPI = Marty.createStateSource
  type: 'http'

  findAll: ->
    request =
       url: Routes.collections_path()
       headers: { 'content-type': 'application/json' }

    @get(request).then (res)->
      CollectionsSourceActionCreators.receiveItems res.body

@jhollingworth jhollingworth added this to the 0.9 milestone Mar 6, 2015
@jhollingworth jhollingworth mentioned this issue Mar 6, 2015
50 tasks
@bigardone
Copy link
Contributor Author

Awesome! thank you very much!

@jhollingworth
Copy link
Contributor

dataType is now in the v0.9 branch (#176). Hopefully this will be out soon

Also I realised my previous example was wrong. It should be

CollectionsAPI = Marty.createStateSource
  type: 'http'

  findAll: ->
    request =
       url: Routes.collections_path()
       headers: { 'Accept': 'application/json' }

    @get(request).then (res)->
      CollectionsSourceActionCreators.receiveItems res.body

@bigardone
Copy link
Contributor Author

With the headers: { 'Accept': 'application/json' } option works like a charm, thanks!

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

No branches or pull requests

2 participants