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

Unable to change Content-Type header #16

Closed
devzsolt opened this issue Feb 8, 2015 · 6 comments
Closed

Unable to change Content-Type header #16

devzsolt opened this issue Feb 8, 2015 · 6 comments

Comments

@devzsolt
Copy link

devzsolt commented Feb 8, 2015

I would like to override Content-Type header when using this.http.put() and post.
The default content type is "text/plain;charset=UTF-8" but I need "application/json".
I tried to attach .withHeaders({ "Content-Type": "application/json" }) to put method, but it didn't work.
Please provide a way to set this header. Thanks!

@EisenbergEffect
Copy link
Contributor

It's a bit of a pain with the current release...but there's a new release coming today or tomorrow morning. With that version it's really easy. You can configure headers to be used by all requests, or per-request.

Here's is a header that will be used for every request:

var client = new HttpClient()
  .configure(x => {
    x.withBaseUrl(baseUrl);
    x.withHeader('Authorization', 'bearer 123');
  });

client.get('some/cool/path');

The configure API will let you set up options to be used on all requests. The same API is available per-request though. So, instead of calling get first, you can do this:

var client = new HttpClient()
  .configure(x => {
    x.withBaseUrl(baseUrl);
  });

client.request
  .withHeader('Authorization', 'bearer 123')
  .get('some/cool/path');

So, in this case the baseUrl will be used for all requests, but the header will only be used for the one invoked get request.

Hope that makes sense. This is part of a major overhaul to the http client. It's releasing today or tomorrow.

@devzsolt
Copy link
Author

Thank you, it totally makes sense for me. I'm looking for the new release ;)

@ghiotion
Copy link

Ditto. And can I tell you how much I'm loving Aurelia? I've been playing with it extensively for the past 48 hours and it's just flat out fantastic.

@EisenbergEffect
Copy link
Contributor

Awesome! We still have a lot of work to do but I'm encouraged by the community response. If you can stick around while we work out the kinks....I think we're going to have something really nice.

@yale
Copy link

yale commented Feb 17, 2015

Hi! I'm not able to set a header on 0.5.2, neither by using the configure function nor the withHeader function:

import {HttpClient} from 'aurelia-http-client';

export class Spacemoney{
  static inject() { return [HttpClient]; }

  constructor(http) {
    this.env = 'development';
    this.apiToken = '...';
    this.http = http.request.withHeader('Authorization', 'Token token="' + this.apiToken + '"');
  }
  ...
}

When the request is made, no Authorization header is set. Let me know if there's any more information I can provide that would help.

BTW, I have been building a sideproject using Aurelia for the past 72 hours, and I am in love. I'm so excited to see this project mature!

@EisenbergEffect
Copy link
Contributor

We have unit tests that do just this, so that's a little baffling. Is it possible for you to write a test case for us that fails?

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