Comments (12)
Have you looked through the unit-tests ... I'm not quite sure if the mentioned Header is something you are looking for but at least it sounds like so, additionally the defaultRequestHeaders should help you define a global setting for the Bearer Authorization header
As for documentation, like with all pre-beta stuff documentation is always sparse, so I'd always advice to take an additional look at the generated unit tests, cause those often helped me to understand what to do.
from http-client.
The problem with the unit-tests is they all new up an HttpClient. I'd like to stick with DI. And yeah defaultRequestHeaders is good for my current need BUT I still think an easy way to define headers for a single call (that allows me to keep DI and the HttpClient without any cleanup) is an important use case. Sounds like something is planned though.
from http-client.
+1
example use case is sending a custom media type (content-type
) on a post (eg application/vnd.contact+json
) or even get requests (accept
).
to get around this I had to create a new client instead of using the one from ioc
import {HttpClient, Headers} from 'aurelia-http-client';
...
var headers = new Headers();
headers.add('content-type', 'application/vnd.contact+json');
var client = new HttpClient(undefined, headers);
I propose the following
http.post(url, content, [replacer], [headers])
where headers is of type headers so it doesn't conflict with replacer... final result might look something like
http.post(url, content, new Headers({ "content-type" : "application/vnd.contact+json"}))
from http-client.
You could simply do this:
import {HttpClient} from 'aurelia-http-client';
export class MyClass{
static inject() { return [HttpClient]; }
constructor(http){
http.defaultRequestHeaders.add('Content-Type', 'application/json; charset=utf-8');
}
}
from http-client.
That is not simple compared to other frameworks AND you need to cleanup the
defaultRequestHeaders because httpclient is a singleton no?
On Fri, Feb 6, 2015 at 6:59 PM, Guillaume Jasmin [email protected]
wrote:
You could simply do this:
import {HttpClient} from 'aurelia-http-client';
export class MyClass{
static inject() { return [HttpClient]; }
constructor(http){
http.defaultRequestHeaders.add('Content-Type', 'application/json; charset=utf-8');
}
}—
Reply to this email directly or view it on GitHub
#11 (comment).
from http-client.
Major upgrade to http client in master, including a fluent api for requests. This will be releasing in the next couple of days.
from http-client.
The current tests in master don't show any improvement for this change unless HttpClient is no longer injected and we should always be creating an instance?
from http-client.
You can configure HttpClient to be transient if you want, and always get a new instance. That's always been possible. However, the new api supports an additional way to make requests with a fluent API that enables customizing each request individually. So, you can do this:
client.request
.withHeader('foo', 'bar')
.withCredentials(true)
.get(uri);
Each chained method returns a request builder, until you call the verb, which returns the promise for the request. The previous API now runs on top of this, so we've confirmed that our original test suite passes with the new design. Some of the tests are using the new API as well. We need to add quite a few more tests to exercise it more fully.
from http-client.
Awesome.. cool :)
from http-client.
docs should be updated. I was figuring out why I can't add defaultRequestHeaders
:)
from http-client.
It'd be nice if there was either a withHeaders call that accepts an array of kvp of header name and value or if withHeader had an overload accepting as much.
from http-client.
Just a note for others, the syntax seems to have changed from what was noted above:
client.createRequest(uri)
.withHeader('foo', 'bar')
.asGet()
.send()
.then(callback);
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.