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

Elaborating the arguments to Http.request for CORS support #61

Closed
rehno-lindeque opened this Issue Dec 22, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@rehno-lindeque
Contributor

rehno-lindeque commented Dec 22, 2014

With the ongoing work on Http, I'd like to bravely throw in a feature request for CORS support :)

The protocol for CORS is actually somewhat involved, particularly since it involves a preflight OPTIONS request which I believe needs to be resent after a timeout period. I think this is usually invisible to the user of most API's, it seems as though things can get tricky.

Using AngularJS's $httpProvider and Restangular, this looks like the following:

  $httpProvider.defaults.useXDomain = true
  Restangular.setDefaultHttpFields {withCredentials: true}
  Restangular.setDefaultHeaders {"Content-Type": "application/json"} # X-Requested-With header can't be used with CORS

While non-CORS restangular requests simply look like

  Restangular.setDefaultHeaders 
  { "Content-Type": "application/json",
  , "X-Requested-With": "XMLHttpRequest"
  }

I think swapping the argument to request in the new API might also be handy.

request : String -> String -> String -> List (String, String) -> Request String

Since request is an elaborated version of get/put/post/delete it seems as though the primary use case is going to be adjusting the headers...
For example, for a regular ajax request, get might look like

get = Http.request
    [ "Content-Type": "application/json",
    , "X-Requested-With": "XMLHttpRequest"
    ]
    "GET"

while a CORS ajax request looks somewhat different

corsGet = Http.request
    [ "Content-Type": "application/json",
    , -- ... ?
    ]
    "GET" -- "OPTIONS" ?
@roobie

This comment has been minimized.

Show comment
Hide comment
@roobie

roobie Jan 15, 2016

Has there been no update on this issue? I am asking because I am facing similar challenges. Maybe I'm just missing something, and if so, please tell.

roobie commented Jan 15, 2016

Has there been no update on this issue? I am asking because I am facing similar challenges. Maybe I'm just missing something, and if so, please tell.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 11, 2016

Member

Not sure if evancz/elm-http or others solve this, but it's no longer a core thing.

Member

evancz commented May 11, 2016

Not sure if evancz/elm-http or others solve this, but it's no longer a core thing.

@evancz evancz closed this May 11, 2016

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