Пример #1
0
func (suite *ApiTestSuite) request(endpoint api.Endpoint, body io.Reader) *http.Request {
	req, _ := http.NewRequest(endpoint.Verb, endpointFmt(suite.server.URL, endpoint.String()), body)
	req.Header.Set("Accept", "application/json")
	if body != nil {
		req.Header.Set("Content-Type", "application/json")
	}
	return req
}
Пример #2
0
func (client ApiClient) request(endpoint api.Endpoint, args ...interface{}) (*http.Request, error) {
	path := endpoint.Build(args...).String()
	if req, err := http.NewRequest(endpoint.Verb, client.url(path), nil); err != nil {
		return nil, err
	} else {
		req.Header.Add("Accept", string(client.Encoding))
		if endpoint.Verb == "POST" || endpoint.Verb == "PATCH" || endpoint.Verb == "PUT" {
			req.Header.Add("Content-Type", string(client.Encoding))
		}
		return req, nil
	}
}