# V2 fetch-client configuration

**URL:** <https://discourse.aurelia.io/t/v2-fetch-client-configuration/5056>\
**Category:** Uncategorized\
**Created:** [January 17, 2023, 9:30pm UTC](https://discourse.aurelia.io/t/v2-fetch-client-configuration/5056 "2023-01-17T21:30:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aGustafson](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@aGustafson](https://discourse.aurelia.io/u/aGustafson)\
**Post date:** [January 17, 2023, 9:30pm UTC](https://discourse.aurelia.io/t/v2-fetch-client-configuration/5056/1 "2023-01-17T21:30:47Z")

</div>

I have an application with several services and plugins that use the HttpClient from @aurelia/fetch-client.

I would like to add a configuration to the fetch-client globally, a baseUrl and some interceptors.

How can I override the HttpClient settings globally?

In v1 I could do something like this within the aurelia configuration function:

```auto
  let http = new HttpClient();
  http.configure(configure => {
    configure
      .withBaseUrl('')
      .withHeader("X-CSRFToken", getCookie("csrftoken"))
      .withHeader('Accept', 'application/json')
      .withHeader('Content-Type', 'application/json')
      .withInterceptor({
        request: (request) => {
          return request;
        },
        response: (response) => {
          return response;
        }
      })
  });

  aurelia.container.registerInstance(HttpClient, http);

```

in v2 there does not seem to be a way to do this with the fetch-client.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [January 18, 2023, 8:04am UTC](https://discourse.aurelia.io/t/v2-fetch-client-configuration/5056/2 "2023-01-18T08:04:29Z")

</div>

Hi @aGustafson! You can do the similar configuration in Au2 as well. Here is the doc for that: [Fetch Client - The Aurelia 2 Docs](https://docs.aurelia.io/aurelia-packages/fetch-client#configuring-the-fetch-client). The example demonstrates that using a `@newInstanceOf` decorator. However, if you prefer doing that in bootstrapping phase you can instead create a new instance of `HttpClient` using simply `new HttpClient();` and then apply the configuration as sown in docs.

If you then want to register the instance to the DI, you need to do something like this:

```typescript
const au = new Aurelia() // or use the static API, as per your preference
  .register(Registration.instance(IHttpClient, yourConfiguredHttpClient));

```

In case that does not work, please share a reproduction. You can easily do so by forking this [StackBlitz project](https://stackblitz.com/edit/au2-conventions?file=src%2Fmy-app.html).

---

<div class="post-metadata">

**Author:** ![aGustafson](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@aGustafson](https://discourse.aurelia.io/u/aGustafson)\
**Post date:** [January 19, 2023, 10:47am UTC](https://discourse.aurelia.io/t/v2-fetch-client-configuration/5056/3 "2023-01-19T10:47:51Z")

</div>

Hi @Sayan751 , thanks!

I will try that.  
I have been trying to register using the DI directly in main.ts. That was not working. I did not know you could use the Registration.instance in the Aurelia().register() methods.
