Coder Social home page Coder Social logo

Comments (6)

EisenbergEffect avatar EisenbergEffect commented on August 23, 2024

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.

devzsolt avatar devzsolt commented on August 23, 2024

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

from http-client.

ghiotion avatar ghiotion commented on August 23, 2024

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.

EisenbergEffect avatar EisenbergEffect commented on August 23, 2024

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.

yale avatar yale commented on August 23, 2024

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.

EisenbergEffect avatar EisenbergEffect commented on August 23, 2024

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)

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.