31 lines
742 B
Go
Raw Normal View History

2023-04-11 21:39:49 +09:00
package fetch
import (
2023-05-28 13:04:35 +09:00
"context"
"io"
2023-04-11 21:39:49 +09:00
"net/http"
)
2023-05-28 13:04:35 +09:00
// Request represents an HTTP request and is part of the Fetch API.
// Docs: https://developers.cloudflare.com/workers/runtime-apis/request/
type Request struct {
*http.Request
}
// NewRequest returns new Request given a method, URL, and optional body
func NewRequest(ctx context.Context, method string, url string, body io.Reader) (*Request, error) {
req, err := http.NewRequestWithContext(ctx, method, url, body)
if err != nil {
return nil, err
}
return &Request{
Request: req,
}, nil
}
2023-04-11 21:39:49 +09:00
// Do sends an HTTP request and returns an HTTP response
2023-05-28 13:04:35 +09:00
func (c *Client) Do(req *Request, init *RequestInit) (*http.Response, error) {
return fetch(c.namespace, req.Request, init)
2023-04-11 21:39:49 +09:00
}