@@ -323,6 +323,79 @@ func (api *APIBuilder) ConfigureContainer(builder ...func(*APIContainer)) *APICo
323
323
return api .apiBuilderDI
324
324
}
325
325
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
+
326
399
// GetRelPath returns the current party's relative path.
327
400
// i.e:
328
401
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
0 commit comments