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
5package model
6
7type HttpClient struct {
8 server ServerNeededHttpClient
9 header map[string][]string
10}
11
12type ServerNeededHttpClient interface {
13 DoRequest(HttpRequest) (HttpResponse, error)
14}
15
16func NewHttpClient(server ServerNeededHttpClient, header map[string][]string) HttpClient {
17 return HttpClient{
18 server: server,
19 header: header,
20 }
21}
22
23func (h HttpClient) Get(url string) (HttpResponse, error) {
24 return h.server.DoRequest(HttpRequest{
25 Method: "GET",
26 Url: url,
27 Body: "",
28 Header: h.header,
29 })
30}
31
32func (h HttpClient) Post(url string, body string) (HttpResponse, error) {
33 return h.server.DoRequest(HttpRequest{
34 Method: "POST",
35 Url: url,
36 Body: body,
37 Header: h.header,
38 })
39}
40
41func (h HttpClient) Put(url string, body string) (HttpResponse, error) {
42 return h.server.DoRequest(HttpRequest{
43 Method: "PUT",
44 Url: url,
45 Body: body,
46 Header: h.header,
47 })
48}
49
50func (h HttpClient) Delete(url string) (HttpResponse, error) {
51 return h.server.DoRequest(HttpRequest{
52 Method: "DELETE",
53 Url: url,
54 Body: "",
55 Header: h.header,
56 })
57}