aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Black <dougblack@gatech.edu>2014-01-25 14:38:03 -0800
committerDoug Black <dougblack@gatech.edu>2014-01-25 14:38:03 -0800
commit777761a8a1be2a8eef9f360ddede7d4dbc7684d2 (patch)
tree0b710b48240d8ef0559c532e1329be2631aee096
parentbetter practices (diff)
downloadsleepy-777761a8a1be2a8eef9f360ddede7d4dbc7684d2.tar.gz
sleepy-777761a8a1be2a8eef9f360ddede7d4dbc7684d2.tar.bz2
sleepy-777761a8a1be2a8eef9f360ddede7d4dbc7684d2.zip
update README
-rw-r--r--README.md38
-rw-r--r--tests/items.go29
-rw-r--r--tests/test.go6
3 files changed, 49 insertions, 24 deletions
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.
diff --git a/tests/items.go b/tests/items.go
new file mode 100644
index 0000000..a6f53f6
--- /dev/null
+++ b/tests/items.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "net/url"
+ "sleepy"
+)
+
+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}
+
+ return 200, data
+}
+
+func main() {
+
+ item := new(Item)
+
+ var api = new(sleepy.Api)
+ api.AddResource(item, "/items")
+ api.Start(3000)
+
+}
diff --git a/tests/test.go b/tests/test.go
index 53c7f9e..4610f3d 100644
--- a/tests/test.go
+++ b/tests/test.go
@@ -15,12 +15,6 @@ func (b Bar) Get(values ...url.Values) (int, interface{}) {
return 200, map[string]string{"hello": "goodbye"}
}
-type Baz struct {
- sleepy.PostNotSupported
- sleepy.PutNotSupported
- sleepy.DeleteNotSupported
-}
-
func main() {
bar := new(Bar)
bgstack15