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 constructor(
13 private server: needServer,
14 private header: Map<string, Array<string>>,
15 ) {}
16
17 get(url: string): HttpResponse {
18 return this.server.doRequest(new HttpRequest("GET", url, "", this.header));
19 }
20
21 post(url: string, body: string): HttpResponse {
22 return this.server.doRequest(
23 new HttpRequest("POST", url, body, this.header),
24 );
25 }
26
27 put(url: string, body: string): HttpResponse {
28 return this.server.doRequest(
29 new HttpRequest("PUT", url, body, this.header),
30 );
31 }
32
33 delete(url: string): HttpResponse {
34 return this.server.doRequest(
35 new HttpRequest("DELETE", url, "", this.header),
36 );
37 }
38}