GitRoot
Craft your forge, Build your project, Grow your community freely
1// SPDX-FileCopyrightText: 2026 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: MIT
4
5import { HttpRequest, HttpResponse } from "./model";
6
7export interface needServer {
8 doRequest(request: HttpRequest): HttpResponse;
9}
10
11export class HttpClient {
12 private server: needServer;
13 private header: Map<string, Array<string>>;
14
15 constructor(server: needServer, header: Map<string, Array<string>>) {
16 this.server = server;
17 this.header = header;
18 }
19
20 get(url: string): HttpResponse {
21 return this.server.doRequest(new HttpRequest("GET", url, "", this.header));
22 }
23
24 post(url: string, body: string): HttpResponse {
25 return this.server.doRequest(
26 new HttpRequest("POST", url, body, this.header),
27 );
28 }
29
30 put(url: string, body: string): HttpResponse {
31 return this.server.doRequest(
32 new HttpRequest("PUT", url, body, this.header),
33 );
34 }
35
36 delete(url: string): HttpResponse {
37 return this.server.doRequest(
38 new HttpRequest("DELETE", url, "", this.header),
39 );
40 }
41}