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)
| 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. |
| 130 | func (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 | |
| 154 | func (Router) urlFrom(resource string, uri string) (string, error) { |
| 155 | u, err := url.Parse(resource) |
no test coverage detected