Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ Sleepy is a micro-framework for building RESTful APIs.
package main

import (
"net/url"
"net/http"
"github.com/dougblack/sleepy"
)

type Item struct { }

func (item Item) Get(values url.Values, headers http.Header) (int, interface{}, http.Header) {
func (item Item) Get(request *http.Request) (int, interface{}, http.Header) {
items := []string{"item1", "item2"}
data := map[string][]string{"items": items}
return 200, data, http.Header{"Content-type": {"application/json"}}
Expand Down
13 changes: 6 additions & 7 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
)

const (
Expand All @@ -18,25 +17,25 @@ const (
// GetSupported is the interface that provides the Get
// method a resource must support to receive HTTP GETs.
type GetSupported interface {
Get(url.Values, http.Header) (int, interface{}, http.Header)
Get(*http.Request) (int, interface{}, http.Header)
}

// PostSupported is the interface that provides the Post
// method a resource must support to receive HTTP POSTs.
type PostSupported interface {
Post(url.Values, http.Header) (int, interface{}, http.Header)
Post(*http.Request) (int, interface{}, http.Header)
}

// PutSupported is the interface that provides the Put
// method a resource must support to receive HTTP PUTs.
type PutSupported interface {
Put(url.Values, http.Header) (int, interface{}, http.Header)
Put(*http.Request) (int, interface{}, http.Header)
}

// DeleteSupported is the interface that provides the Delete
// method a resource must support to receive HTTP DELETEs.
type DeleteSupported interface {
Delete(url.Values, http.Header) (int, interface{}, http.Header)
Delete(*http.Request) (int, interface{}, http.Header)
}

// An API manages a group of resources by routing requests
Expand All @@ -63,7 +62,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return
}

var handler func(url.Values, http.Header) (int, interface{}, http.Header)
var handler func(*http.Request) (int, interface{}, http.Header)

switch request.Method {
case GET:
Expand All @@ -89,7 +88,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return
}

code, data, header := handler(request.Form, request.Header)
code, data, header := handler(request)

content, err := json.Marshal(data)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package sleepy
import (
"io/ioutil"
"net/http"
"net/url"
"testing"
)

type Item struct{}

func (item Item) Get(values url.Values, headers http.Header) (int, interface{}, http.Header) {
func (item Item) Get(*http.Request) (int, interface{}, http.Header) {
items := []string{"item1", "item2"}
data := map[string][]string{"items": items}
return 200, data, nil
Expand Down