Comments (6)
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.
from http-client.
Thank you, it totally makes sense for me. I'm looking for the new release ;)
from http-client.
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.
from http-client.
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.
from http-client.
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!
from http-client.
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?
from http-client.
Related Issues (20)
- How can i abort http-client request? HOT 3
- responseType field is missing in HttpResponseMessage declaration HOT 3
- Headers are not treated as case insensitive HOT 4
- Custom headers not accessible in CORS response HOT 5
- response Type is set to wrong one(json) when the actual response is a string with Content-Type "text/plain" HOT 3
- http-client should create xhr hook to support cross cutting features HOT 3
- Interceptor return types are incorrect. HOT 11
- Add setting for traditional buildQueryString HOT 4
- Passing ArrayBuffer as content produces unintuitive behavior HOT 2
- Abort works incorrectly for delayed requests HOT 2
- Download progress callback missing
- Feature Request: .withForm() and .withFormData() HOT 2
- TC39 proposal cancellation HOT 1
- Interceptors cannot short-circuit request/response HOT 1
- [Breaking] version 1.2 query changes breaks client.configure(o => o.withParams(params)) HOT 4
- Make request available in interceptor responseError HOT 1
- Cancel method is not propagated to then promises HOT 1
- statusCode 500, throw statusCode 0 HOT 2
- multipart/form-data queries have a null Content-Length in some cases
- Content-Type header is overridden to text/plain in no-cors mode HOT 5
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 http-client.