Skip to content

Commit f6628b9

Browse files
authored
Update README.md
1 parent 7833114 commit f6628b9

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
1-
# rest-api-framework
1+
# REST API Framework
22
REST 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+
```

0 commit comments

Comments
 (0)