File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed
Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change 1- # rest-api-framework
1+ # REST API Framework
22REST API framework for go lang
3+
4+ # Framework is under development
5+ ## Status:
6+ - Working on POC as per concept
7+ ```
8+ var api rest.API
9+
10+ // request interceptor / middleware
11+ api.Use(func(ctx *rest.Context) {
12+ ctx.Set("authtoken", "roshangade")
13+ })
14+
15+ // routes
16+ api.GET("/", func(ctx *rest.Context) {
17+ ctx.Send("Hello World!")
18+ })
19+
20+ api.GET("/foo", func(ctx *rest.Context) {
21+ ctx.Status(401).Throw(errors.New("UNAUTHORIZED"))
22+ })
23+
24+ api.GET("/:bar", func(ctx *rest.Context) {
25+ fmt.Println("authtoken", ctx.Get("authtoken"))
26+ ctx.SendJSON(ctx.Params)
27+ })
28+
29+ // error handler
30+ api.Error("UNAUTHORIZED", func(ctx *rest.Context) {
31+ ctx.Send("You are unauthorized")
32+ })
33+
34+ fmt.Println("Starting server.")
35+
36+ http.ListenAndServe(":8080", api)
37+ ```
You can’t perform that action at this time.
0 commit comments