MCPcopy Create free account
hub / github.com/cloudfoundry/cli / CreateRequest

Method CreateRequest

api/uaa/internal/routing.go:130–152  ·  view source on GitHub ↗

CreateRequest returns a request key'd off of the name given. The params are merged into the URL and body is set as the request body.

(name string, params Params, body io.Reader)

Source from the content-addressed store, hash-verified

128// CreateRequest returns a request key'd off of the name given. The params are
129// merged into the URL and body is set as the request body.
130func (router Router) CreateRequest(name string, params Params, body io.Reader) (*http.Request, error) {
131 route, ok := router.routes[name]
132 if !ok {
133 return &http.Request{}, fmt.Errorf("No route exists with the name %s", name)
134 }
135
136 uri, err := route.CreatePath(params)
137 if err != nil {
138 return &http.Request{}, err
139 }
140
141 resource, ok := router.resources[route.Resource]
142 if !ok {
143 return &http.Request{}, fmt.Errorf("No resource exists with the name %s", route.Resource)
144 }
145
146 url, err := router.urlFrom(resource, uri)
147 if err != nil {
148 return &http.Request{}, err
149 }
150
151 return http.NewRequest(route.Method, url, body)
152}
153
154func (Router) urlFrom(resource string, uri string) (string, error) {
155 u, err := url.Parse(resource)

Callers 3

newRequestMethod · 0.45
routing_test.goFile · 0.45
newHTTPRequestMethod · 0.45

Calls 3

urlFromMethod · 0.95
NewRequestMethod · 0.80
CreatePathMethod · 0.45

Tested by

no test coverage detected