Skip to content

Commit

Permalink
expose Api#baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Dashney committed Mar 6, 2020
1 parent 9ce6c7e commit 29850d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const [{data, loading, error}] = useApiQuery({url: `/users/${id}`})
- [`RestEndpoints`](#restendpoints)
- [`Api`](#api)
- [`Constructor`](#constructor)
- [`baseUrl`](#baseurl)
- [`request(params: object, opts?: object)`](#requestparams-object-opts-object)
- [`requestInProgress(params: object)`](#requestinprogressparams-object)
- [`writeCachedResponse(params: object, responseBody?: Blob | object | string)`](#writecachedresponseparams-object-responsebody-blob--object--string)
Expand Down Expand Up @@ -865,6 +866,10 @@ Constructor fields:
</details>
#### `baseUrl`
The `baseUrl` that was set via the `Api` constructor.
#### `request(params: object, opts?: object)`
Makes an API request and returns the parsed response body.
Expand Down
4 changes: 4 additions & 0 deletions src/api/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ it('applies the base URL to requests', async () => {
expect(request.url).toEqual('http://test.com/endpoint')
})

it('exposes the base url', () => {
expect(api.baseUrl).toEqual('http://test.com')
})

describe('defaultFetchPolicy', () => {
it('defaults to fetch-first', () => {
expect(new Api().defaultFetchPolicy).toEqual('fetch-first')
Expand Down
4 changes: 4 additions & 0 deletions src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class Api {
)
}

get baseUrl() {
return this.requestManager.baseUrl
}

/**
* Makes an API request
*/
Expand Down

0 comments on commit 29850d6

Please sign in to comment.