diff options
| author | Shulhan <ms@kilabit.info> | 2024-01-25 18:59:23 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-01-25 18:59:23 +0700 |
| commit | 7d3ce2ca01f2d4954d89430e48ca23c89416668b (patch) | |
| tree | 4f6e5eaccf08816e8bd36bd03c37d2729e9978e3 /example | |
| parent | ae60ff83f53d14bb9427c02695414afb20147051 (diff) | |
| download | gorankusu-7d3ce2ca01f2d4954d89430e48ca23c89416668b.tar.xz | |
all: support parameter binding in HTTP Path
If HTTP Path contains key, for example "/:book", and the Params contains
the same key, the Path will be filled with value from Params.
The same key in Params will be deleted and not send on query parameter
or body.
Diffstat (limited to 'example')
| -rw-r--r-- | example/example.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/example/example.go b/example/example.go index 332cbb3..1be51ef 100644 --- a/example/example.go +++ b/example/example.go @@ -31,8 +31,9 @@ import ( ) const ( - pathExample = "/example" - pathExampleError = "/example/error" + pathExample = `/example` + pathExampleError = `/example/error` + pathExampleNamePage = `/example/:name/page` ) const ( @@ -153,6 +154,14 @@ func (ex *Example) registerEndpoints() (err error) { Call: ex.pathExamplePost, }) + err = ex.trunks.Httpd.RegisterEndpoint(&libhttp.Endpoint{ + Method: libhttp.RequestMethodPost, + Path: pathExampleNamePage, + RequestType: libhttp.RequestTypeJSON, + ResponseType: libhttp.ResponseTypeJSON, + Call: ex.pathExamplePost, + }) + return err } @@ -289,6 +298,24 @@ func (ex *Example) registerTargets() (err error) { }, }, IsCustomizable: true, + }, { + Name: `HTTP Post path binding`, + Hint: `Test parameter with parameter in path`, + Method: libhttp.RequestMethodPost, + Path: pathExampleNamePage, + RequestType: libhttp.RequestTypeJSON, + Params: trunks.KeyFormInput{ + `name`: trunks.FormInput{ + Label: `Name`, + Hint: `This parameter send in path.`, + Value: `testname`, + }, + `id`: trunks.FormInput{ + Label: `ID`, + Hint: `This parameter send in body as JSON.`, + Value: `123`, + }, + }, }}, } |
