Coder Social home page Coder Social logo

Comments (12)

zewa666 avatar zewa666 commented on August 23, 2024

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.

ShaneCourtrille avatar ShaneCourtrille commented on August 23, 2024

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.

jhoguet avatar jhoguet commented on August 23, 2024

+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.

GuillaumeJasmin avatar GuillaumeJasmin commented on August 23, 2024

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.

ShaneCourtrille avatar ShaneCourtrille commented on August 23, 2024

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.

EisenbergEffect avatar EisenbergEffect commented on August 23, 2024

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.

ShaneCourtrille avatar ShaneCourtrille commented on August 23, 2024

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.

EisenbergEffect avatar EisenbergEffect commented on August 23, 2024

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.

ShaneCourtrille avatar ShaneCourtrille commented on August 23, 2024

Awesome.. cool :)

from http-client.

matjaz avatar matjaz commented on August 23, 2024

docs should be updated. I was figuring out why I can't add defaultRequestHeaders :)

from http-client.

MikeJoyce19 avatar MikeJoyce19 commented on August 23, 2024

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.

slundberg avatar slundberg commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.