diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -2,43 +2,45 @@ #### A RESTful framework for Go -Sleepy is not done yet. Here is a potential target API. +Sleepy is a micro-framework for building RESTful APIs. ```go +package main import ( - "net/http" + "net/url" "sleepy" ) -type Item struct { } +type Item struct { + sleepy.PostNotSupported + sleepy.PutNotSupported + sleepy.DeleteNotSupported +} + +func (item Item) Get(values ...url.Values) (int, interface{}) { + items := []string{"item1", "item2"} + data := map[string][]string{"items": items} -func (item *Item) Get(foo string, bar int) (interface{}, int, http.Headers) { - data := map[string]int { - foo : bar - } - return data, 200, nil + return 200, data } func main() { - item = new(Item) + item := new(Item) var api = new(sleepy.Api) - api.AddResource(item, "/item") - - request, _ := http.NewRequest("GET", "/item", "foo=thing&bar=5") - fmt.Println(api.HandleRequest(request)) + api.AddResource(item, "/items") + api.Start(3000) } ``` -With a response of +Now if we curl that endpoint: -```javascript -{ - "thing": 5 -} +```bash +curl localhost:3000/items +{"items": ["item1", "item2"]} ``` Stay tuned. |