Skip to content

Commit 9f6a75f

Browse files
committed
Expose the ConfigureContainer().Handle as Application/Party.HandleFunc to make it easier for developers to catch up
1 parent da3d6e6 commit 9f6a75f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Iris is a fast, simple yet fully featured and very efficient web framework for G
1818

1919
It provides a beautifully expressive and easy to use foundation for your next website or API.
2020

21+
![](https://user-images.githubusercontent.com/22900943/105253731-b8db6d00-5b88-11eb-90c1-0c92a5581c86.png)
22+
2123
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.
2224

2325
[![](https://iris-go.com/images/reviews.gif)](https://iris-go.com/testimonials/)

core/router/api_builder.go

+73
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,79 @@ func (api *APIBuilder) ConfigureContainer(builder ...func(*APIContainer)) *APICo
323323
return api.apiBuilderDI
324324
}
325325

326+
// HandleFunc registers a route on HTTP verb "method" and relative, to this Party, path.
327+
// It is like the `Handle` method but it accepts one or more "handlersFn" functions
328+
// that each one of them can accept any input arguments as the HTTP request and
329+
// output a result as the HTTP response. Specifically,
330+
// the input of the "handlersFn" can be any registered dependency
331+
// (see ConfigureContainer().RegisterDependency)
332+
// or leave the framework to parse the request and fill the values accordingly.
333+
// The output of the "handlersFn" can be any output result:
334+
// custom structs <T>, string, []byte, int, error,
335+
// a combination of the above, hero.Result(hero.View | hero.Response) and more.
336+
//
337+
// If more than one handler function is registered
338+
// then the execution happens without the nessecity of the `Context.Next` method,
339+
// simply, to stop the execution and not continue to the next "handlersFn" in chain
340+
// you should return an `iris.ErrStopExecution`.
341+
//
342+
// Example Code:
343+
//
344+
// The client's request body and server's response body Go types.
345+
// Could be any data structure.
346+
//
347+
// type (
348+
// request struct {
349+
// Firstname string `json:"firstname"`
350+
// Lastname string `json:"lastname"`
351+
// }
352+
//
353+
// response struct {
354+
// ID uint64 `json:"id"`
355+
// Message string `json:"message"`
356+
// }
357+
// )
358+
//
359+
// Register the route hander.
360+
//
361+
// HTTP VERB ROUTE PATH ROUTE HANDLER
362+
// app.HandleFunc("PUT", "/users/{id:uint64}", updateUser)
363+
//
364+
// Code the route handler function.
365+
// Path parameters and request body are binded
366+
// automatically.
367+
// The "id" uint64 binds to "{id:uint64}" route path parameter and
368+
// the "input" binds to client request data such as JSON.
369+
//
370+
// func updateUser(id uint64, input request) response {
371+
// // [custom logic...]
372+
//
373+
// return response{
374+
// ID:id,
375+
// Message: "User updated successfully",
376+
// }
377+
// }
378+
//
379+
// Simulate a client request which sends data
380+
// to the server and prints out the response.
381+
//
382+
// curl --request PUT -d '{"firstname":"John","lastname":"Doe"}' \
383+
// -H "Content-Type: application/json" \
384+
// http://localhost:8080/users/42
385+
//
386+
// {
387+
// "id": 42,
388+
// "message": "User updated successfully"
389+
// }
390+
//
391+
// See the `ConfigureContainer` for more features regrading
392+
// the dependency injection, mvc and function handlers.
393+
//
394+
// This method is just a shortcut for the `ConfigureContainer().Handle` one.
395+
func (api *APIBuilder) HandleFunc(method, relativePath string, handlersFn ...interface{}) *Route {
396+
return api.ConfigureContainer().Handle(method, relativePath, handlersFn...)
397+
}
398+
326399
// GetRelPath returns the current party's relative path.
327400
// i.e:
328401
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".

0 commit comments

Comments
 (0)