Skip to main content

path

path is a directive executor who decodes/encodes a field from/to the path of the request URI, aka. path variables.

danger

httpin has registered a path directive by default. However, it only supports the encoding. An error will be returned if you try to decode some structs with path directives.

Q: Why we don't support decoding of path variables by default?

A: Because the decoding of path variables relys on the routing functionality of the web framework you are using. It cannot be done by httpin alone.

Even though, httpin can be easily integrated with other packages that provide routing functionality, to decode path variables. See below for more details.

You can quickly implement a path directive with the following code (routing package specific):

  • go-chi/chi
import httpin_integration "github.com/ggicci/httpin/integration"

func init() {
httpin_integration.UseGochiURLParam("path", chi.URLParam)
}
  • gorilla/mux
import httpin_integration "github.com/ggicci/httpin/integration"

func init() {
httpin_integration.UseGorillaMux("path", mux.Vars)
}

See Integrations section on the menu left to learn more details and examples on how to integrate httpin with other packages.

If you can't find the package you wanted on the list, you could either open an issue on the Github or visit Custom 🔌 to learn to implement a "path" directive of your own.

We do hope that you would like to make contributions to the httpin project to make it better!