From 777761a8a1be2a8eef9f360ddede7d4dbc7684d2 Mon Sep 17 00:00:00 2001 From: Doug Black Date: Sat, 25 Jan 2014 14:38:03 -0800 Subject: update README --- README.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index df45e76..c3fb65b 100644 --- a/README.md +++ b/README.md @@ -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. -- cgit