mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-25 13:51:12 +00:00
Including API version in HTTP constructor.
This commit is contained in:
parent
414c601429
commit
9be225add3
3 changed files with 9 additions and 4 deletions
|
@ -32,6 +32,7 @@ this.ws.send(client.login(form));
|
|||
```js
|
||||
import { LemmyHttp } from 'lemmy-js-client';
|
||||
|
||||
let baseUrl = 'https://lemmy.ml';
|
||||
let client: LemmyHttp = new LemmyHttp(baseUrl, headers?);
|
||||
let jwt = await client.httpLogin(loginForm).jwt;
|
||||
```
|
||||
|
|
10
src/http.ts
10
src/http.ts
|
@ -92,6 +92,8 @@ import {
|
|||
PersonMentionResponse,
|
||||
} from './interfaces/api/person';
|
||||
|
||||
import { VERSION } from './interfaces/others';
|
||||
|
||||
enum HttpType {
|
||||
Get = 'GET',
|
||||
Post = 'POST',
|
||||
|
@ -99,16 +101,16 @@ enum HttpType {
|
|||
}
|
||||
|
||||
export class LemmyHttp {
|
||||
private baseUrl: string;
|
||||
private apiUrl: string;
|
||||
private headers: { [key: string]: string } = {};
|
||||
|
||||
/**
|
||||
* Generates a new instance of LemmyHttp
|
||||
* @param baseUrl the full base url: https://lemmy.ml/api/v2
|
||||
* @param baseUrl the base url, without the vX version: https://lemmy.ml -> goes to https://lemmy.ml/api/vX
|
||||
* @param headers optional headers. Should contain x-real-ip and x-forwarded-for
|
||||
*/
|
||||
constructor(baseUrl: string, headers?: { [key: string]: string }) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.apiUrl = `${baseUrl}/api/${VERSION}`;
|
||||
|
||||
if (headers) {
|
||||
this.headers = headers;
|
||||
|
@ -366,7 +368,7 @@ export class LemmyHttp {
|
|||
}
|
||||
|
||||
private buildFullUrl(endpoint: string): string {
|
||||
return `${this.baseUrl}${endpoint}`;
|
||||
return `${this.apiUrl}${endpoint}`;
|
||||
}
|
||||
|
||||
private async wrapper<ResponseType, MessageType>(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export const VERSION = 'v3';
|
||||
|
||||
/**
|
||||
* All of the websocket operations available
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue