update readme
and something else on the little things
This commit is contained in:
parent
ac25d1bfc6
commit
8eccf45b0c
19
README.md
19
README.md
@ -1 +1,20 @@
|
|||||||
# go-jsonapi-example
|
# go-jsonapi-example
|
||||||
|
|
||||||
|
`make && make run`
|
||||||
|
|
||||||
|
## Create a new car:
|
||||||
|
`curl -X POST http://localhost:8080/v1/cars -d '{"data" : {"type" : "cars" , "attributes": {"brand" : "bmw", "model": "x5", "price": 999, "status": "OnTheWay"}}}'`
|
||||||
|
|
||||||
|
## List cars:
|
||||||
|
`curl -X GET http://localhost:8080/v1/cars`
|
||||||
|
|
||||||
|
## List paginated cars:
|
||||||
|
`curl -X GET 'http://localhost:8080/v1/cars?page\[offset\]=0&page\[limit\]=2'`
|
||||||
|
## OR
|
||||||
|
`curl -X GET 'http://localhost:8080/v1/cars?page\[number\]=1&page\[size\]=2'`
|
||||||
|
|
||||||
|
## Update:
|
||||||
|
`curl -X PATCH http://localhost:8080/v1/cars/1 -d '{ "data" : {"type" : "cars", "id": "1", "attributes": {"model" : "x3"}}}'`
|
||||||
|
|
||||||
|
## Delete:
|
||||||
|
`curl -X DELETE http://localhost:8080/v1/cars/2`
|
||||||
|
@ -42,7 +42,7 @@ func (c Car) Verify() (bool, api2go.HTTPError) {
|
|||||||
newErr := newVerifyError(
|
newErr := newVerifyError(
|
||||||
"Invalid Attribute",
|
"Invalid Attribute",
|
||||||
"attribute must be one of: OnTheWay, InStock, Sold, Discontinued",
|
"attribute must be one of: OnTheWay, InStock, Sold, Discontinued",
|
||||||
"/data/attributes/brand")
|
"/data/attributes/status")
|
||||||
verifyErrors = append(verifyErrors, newErr)
|
verifyErrors = append(verifyErrors, newErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ type CarResource struct {
|
|||||||
|
|
||||||
// FindAll to satisfy api2go data source interface
|
// FindAll to satisfy api2go data source interface
|
||||||
func (s CarResource) FindAll(r api2go.Request) (api2go.Responder, error) {
|
func (s CarResource) FindAll(r api2go.Request) (api2go.Responder, error) {
|
||||||
var result []model.Car
|
|
||||||
cars := s.CarStorage.GetAll()
|
cars := s.CarStorage.GetAll()
|
||||||
|
result := make([]model.Car, 0, len(cars))
|
||||||
|
|
||||||
for _, car := range cars {
|
for _, car := range cars {
|
||||||
result = append(result, *car)
|
result = append(result, *car)
|
||||||
@ -106,7 +106,6 @@ func (s CarResource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindOne to satisfy `api2go.DataSource` interface
|
// FindOne to satisfy `api2go.DataSource` interface
|
||||||
// this method should return the car with the given ID, otherwise an error
|
|
||||||
func (s CarResource) FindOne(ID string, r api2go.Request) (api2go.Responder, error) {
|
func (s CarResource) FindOne(ID string, r api2go.Request) (api2go.Responder, error) {
|
||||||
car, err := s.CarStorage.GetOne(ID)
|
car, err := s.CarStorage.GetOne(ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user