Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Document with code sample a production way of sharing the API client instance across the app + can this be the same as the Authentication context #7

Open
devraj opened this issue Jul 30, 2022 · 2 comments
Assignees

Comments

@devraj
Copy link
Member

devraj commented Jul 30, 2022

The API Client is instantiated (both for autorest and otc) and it can keep track of authentication tokens and automatically add that to the header as required. Both clients generate wrappers for calling the API endpoints.

Using React context we could pass the API client (I need to critique this after the initial implementation, but on first thoughts it seems to be a legitimate option).

An reference implementation to be provided and this ticket needs to be revisited.

@devraj devraj changed the title Document with code sample a production way of sharing the API client instance across the app Document with code sample a production way of sharing the API client instance across the app + can this be the same as the Authentication context Jul 30, 2022
@devraj
Copy link
Member Author

devraj commented Jul 30, 2022

Study the sample Auth Context provider in React Router DOM documentation to make a judgement call.

@devraj
Copy link
Member Author

devraj commented Jul 30, 2022

A first cut implementation in the first project trialing labs proves to feel right:

import { createContext } from "react";  
import { AcaciaApiClient } from 'api/otc';

// Application level context
export interface AppContextInterface {
    apiClient: AcaciaApiClient;
}
  
export const AppContext = createContext<AppContextInterface | null>(null);

@devraj devraj self-assigned this Sep 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant