Retrieve Path Parameters using inbuild http/Net package

1,582 views
Skip to first unread message

Gladiators Squad

unread,
Nov 16, 2022, 4:08:38 AM11/16/22
to golang-nuts
Hello Everyone,

I'm developing a http server using inbuilt http/net package in golang.
Is there any way to get the path parameters from end points without using any external third-party web framework?

Thanks.

Peter Galbavy

unread,
Nov 17, 2022, 3:23:17 AM11/17/22
to golang-nuts
If you look in the http.Request passed to your handler, there is a URL field - use the net/url package to pull this out:

Stéphane Jeandeaux

unread,
Nov 17, 2022, 3:44:05 AM11/17/22
to Peter Galbavy, golang-nuts
Hi,

Path parameters: http://<host>/path_parameter_1/path_parameter_2/?query_param1=...
The default library does not handle path parameters. 

If you don't want to use an external library, you can implement your own parsing by using url.EscapedPath.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/acba5b94-0f4e-4034-ae48-c407675d411fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages