From 7d3ce2ca01f2d4954d89430e48ca23c89416668b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 25 Jan 2024 18:59:23 +0700 Subject: 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. --- example/example.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'example/example.go') 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`, + }, + }, }}, } -- cgit v1.3