diff --git a/request.go b/request.go index f8fb174..4469b3a 100644 --- a/request.go +++ b/request.go @@ -41,3 +41,70 @@ type Request struct { Result interface{} Error interface{} } + +const ( + // MethodGet HTTP method + MethodGet = "GET" + + // MethodPost HTTP method + MethodPost = "POST" + + // MethodPut HTTP method + MethodPut = "PUT" + + // MethodDelete HTTP method + MethodDelete = "DELETE" + + // MethodPatch HTTP method + MethodPatch = "PATCH" + + // MethodHead HTTP method + MethodHead = "HEAD" + + // MethodOptions HTTP method + MethodOptions = "OPTIONS" +) + + +func (r *Request) Get(url string) (*Response, error) { + return r.Execute(MethodGet, url) +} + +func (r *Request) Head(url string) (*Response, error) { + return r.Execute(MethodHead, url) +} + +func (r *Request) Post(url string) (*Response, error) { + return r.Execute(MethodPost, url) +} + +func (r *Request) Put(url string) (*Response, error) { + return r.Execute(MethodPut, url) +} + +func (r *Request) Delete(url string) (*Response, error) { + return r.Execute(MethodDelete, url) +} + +func (r *Request) Options(url string) (*Response, error) { + return r.Execute(MethodOptions, url) +} + +func (r *Request) Patch(url string) (*Response, error) { + return r.Execute(MethodPatch, url) +} + +func (r *Request) Send() (*Response, error) { + return r.Execute(r.Method, r.Url) +} + +func (r *Request) Execute(method, url string) (*Response, error) { + r.Method = method + r.Url = url + res := &Response{ + Request: r, + RawResponse: &protocol.Response{}, + } + err :=r.client.client.Do(context.Background(),r.RawRequest,res.RawResponse) + return res,err +} \ No newline at end of file