HTTP defines the HTTP transport specific properties of an API, a service or a single method. The function maps the method payload and result types to HTTP properties such as parameters (via path wildcards or query strings), request or response headers, request or response bodies as well as response
(fns ...func())
| 144 | // }) |
| 145 | // }) |
| 146 | func HTTP(fns ...func()) { |
| 147 | if len(fns) > 1 { |
| 148 | eval.TooManyArgError() |
| 149 | return |
| 150 | } |
| 151 | fn := func() {} |
| 152 | if len(fns) == 1 { |
| 153 | fn = fns[0] |
| 154 | } |
| 155 | switch actual := eval.Current().(type) { |
| 156 | case *expr.APIExpr: |
| 157 | eval.Execute(fn, expr.Root) |
| 158 | case *expr.ServiceExpr: |
| 159 | res := expr.Root.API.HTTP.ServiceFor(actual, expr.Root.API.HTTP) |
| 160 | res.DSLFunc = fn |
| 161 | case *expr.MethodExpr: |
| 162 | res := expr.Root.API.HTTP.ServiceFor(actual.Service, expr.Root.API.HTTP) |
| 163 | act := res.EndpointFor(actual) |
| 164 | act.DSLFunc = fn |
| 165 | default: |
| 166 | eval.IncompatibleDSL() |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Consumes adds a MIME type to the list of MIME types the APIs supports when |
| 171 | // accepting requests. While the DSL supports any MIME type, the code generator |