Skip to content

Commit

Permalink
Add version prefix programmatically to the Fetcher class
Browse files Browse the repository at this point in the history
Instead of hardcoding the version prefix of all endpoints to `v1` this
commit allows us to programmatically define a version prefix per
endpoint.

The version prefix represents the lowest common denominator for each
endpoint of the majority of the available seed nodes.

We still default to `v1` with this commit so this just paves the way if
we eventually want to call a `v2` endpoint of a endpoint.
  • Loading branch information
sebastinez committed Sep 2, 2024
1 parent 82ca7c3 commit 57175b0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion http-client/lib/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface RequestOptions {

export interface FetchParams {
method: Method;
// Supported httpd version prefix for this request.
version?: string;
// Path to append to the `Fetcher`s base URL to get the final URL.
path?: string;
// Object that is serialized into JSON and sent as the data.
Expand Down Expand Up @@ -156,6 +158,7 @@ export class Fetcher {
method,
path,
body,
version = "v1",
options = {},
query,
headers = {},
Expand All @@ -166,7 +169,7 @@ export class Fetcher {

const pathSegment = path === undefined ? "" : `/${path}`;

let url = `${this.#baseUrl.scheme}://${this.#baseUrl.hostname}:${this.#baseUrl.port}/api/v1${pathSegment}`;
let url = `${this.#baseUrl.scheme}://${this.#baseUrl.hostname}:${this.#baseUrl.port}/api/${version}${pathSegment}`;

if (query) {
const searchparams = new URLSearchParams(query as Record<string, string>);
Expand Down

0 comments on commit 57175b0

Please sign in to comment.