mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Expose the ConfigureContainer().Handle as Application/Party.HandleFunc to make it easier for developers to catch up
This commit is contained in:
parent
da3d6e69c3
commit
9f6a75f7c4
|
@ -18,6 +18,8 @@ Iris is a fast, simple yet fully featured and very efficient web framework for G
|
||||||
|
|
||||||
It provides a beautifully expressive and easy to use foundation for your next website or API.
|
It provides a beautifully expressive and easy to use foundation for your next website or API.
|
||||||
|
|
||||||
|
![](https://user-images.githubusercontent.com/22900943/105253731-b8db6d00-5b88-11eb-90c1-0c92a5581c86.png)
|
||||||
|
|
||||||
Learn what [others saying about Iris](https://www.iris-go.com/#review) and **[star](https://github.com/kataras/iris/stargazers)** this open-source project to support its potentials.
|
Learn what [others saying about Iris](https://www.iris-go.com/#review) and **[star](https://github.com/kataras/iris/stargazers)** this open-source project to support its potentials.
|
||||||
|
|
||||||
[![](https://iris-go.com/images/reviews.gif)](https://iris-go.com/testimonials/)
|
[![](https://iris-go.com/images/reviews.gif)](https://iris-go.com/testimonials/)
|
||||||
|
|
|
@ -323,6 +323,79 @@ func (api *APIBuilder) ConfigureContainer(builder ...func(*APIContainer)) *APICo
|
||||||
return api.apiBuilderDI
|
return api.apiBuilderDI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleFunc registers a route on HTTP verb "method" and relative, to this Party, path.
|
||||||
|
// It is like the `Handle` method but it accepts one or more "handlersFn" functions
|
||||||
|
// that each one of them can accept any input arguments as the HTTP request and
|
||||||
|
// output a result as the HTTP response. Specifically,
|
||||||
|
// the input of the "handlersFn" can be any registered dependency
|
||||||
|
// (see ConfigureContainer().RegisterDependency)
|
||||||
|
// or leave the framework to parse the request and fill the values accordingly.
|
||||||
|
// The output of the "handlersFn" can be any output result:
|
||||||
|
// custom structs <T>, string, []byte, int, error,
|
||||||
|
// a combination of the above, hero.Result(hero.View | hero.Response) and more.
|
||||||
|
//
|
||||||
|
// If more than one handler function is registered
|
||||||
|
// then the execution happens without the nessecity of the `Context.Next` method,
|
||||||
|
// simply, to stop the execution and not continue to the next "handlersFn" in chain
|
||||||
|
// you should return an `iris.ErrStopExecution`.
|
||||||
|
//
|
||||||
|
// Example Code:
|
||||||
|
//
|
||||||
|
// The client's request body and server's response body Go types.
|
||||||
|
// Could be any data structure.
|
||||||
|
//
|
||||||
|
// type (
|
||||||
|
// request struct {
|
||||||
|
// Firstname string `json:"firstname"`
|
||||||
|
// Lastname string `json:"lastname"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// response struct {
|
||||||
|
// ID uint64 `json:"id"`
|
||||||
|
// Message string `json:"message"`
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// Register the route hander.
|
||||||
|
//
|
||||||
|
// HTTP VERB ROUTE PATH ROUTE HANDLER
|
||||||
|
// app.HandleFunc("PUT", "/users/{id:uint64}", updateUser)
|
||||||
|
//
|
||||||
|
// Code the route handler function.
|
||||||
|
// Path parameters and request body are binded
|
||||||
|
// automatically.
|
||||||
|
// The "id" uint64 binds to "{id:uint64}" route path parameter and
|
||||||
|
// the "input" binds to client request data such as JSON.
|
||||||
|
//
|
||||||
|
// func updateUser(id uint64, input request) response {
|
||||||
|
// // [custom logic...]
|
||||||
|
//
|
||||||
|
// return response{
|
||||||
|
// ID:id,
|
||||||
|
// Message: "User updated successfully",
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Simulate a client request which sends data
|
||||||
|
// to the server and prints out the response.
|
||||||
|
//
|
||||||
|
// curl --request PUT -d '{"firstname":"John","lastname":"Doe"}' \
|
||||||
|
// -H "Content-Type: application/json" \
|
||||||
|
// http://localhost:8080/users/42
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// "id": 42,
|
||||||
|
// "message": "User updated successfully"
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// See the `ConfigureContainer` for more features regrading
|
||||||
|
// the dependency injection, mvc and function handlers.
|
||||||
|
//
|
||||||
|
// This method is just a shortcut for the `ConfigureContainer().Handle` one.
|
||||||
|
func (api *APIBuilder) HandleFunc(method, relativePath string, handlersFn ...interface{}) *Route {
|
||||||
|
return api.ConfigureContainer().Handle(method, relativePath, handlersFn...)
|
||||||
|
}
|
||||||
|
|
||||||
// GetRelPath returns the current party's relative path.
|
// GetRelPath returns the current party's relative path.
|
||||||
// i.e:
|
// i.e:
|
||||||
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
||||||
|
|
Loading…
Reference in New Issue
Block a user