packages feed

json-api-0.1.0.4: example/README.md

#### Running the example

There's a `stack.yaml` file in this directory, so you can run and build this
example project in a familiar manner.

```bash
# pull your GHC deps
stack setup

# build the project
stack build

# run the webserver
stack exec example-exe
```

At this point you should have a webserver running at `http://localhost:8080`
You'll find available endpoints at the following urls:
- [http://localhost:8080/users](http://localhost:8080/users) - responds with a list of User resources
- [http://localhost:8080/users/1](http://localhost:8080/users/1) - responds with a singleton resource
- [http://localhost:8080/users/2](http://localhost:8080/users/2) - responds with a singleton resource
- [http://localhost:8080/users/3](http://localhost:8080/users/3) - responds with a 404 and error payload




## List Resource Example

```JSON
GET /users

{
   "data" : [
      {
         "type" : "User",
         "relationships" : {
            "email" : {
               "links" : {
                  "self" : "/emails/42"
               },
               "data" : {
                  "type" : "Email",
                  "id" : "42"
               }
            }
         },
         "links" : {
            "self" : "/users/1"
         },
         "meta" : null,
         "id" : "1",
         "attributes" : {
            "userFirstName" : "Isaac",
            "userLastName" : "Newton",
            "userId" : 1
         }
      },
      {
         "relationships" : {
            "email" : {
               "links" : {
                  "self" : "/emails/88"
               },
               "data" : {
                  "id" : "88",
                  "type" : "Email"
               }
            }
         },
         "type" : "User",
         "attributes" : {
            "userFirstName" : "Albert",
            "userLastName" : "Einstein",
            "userId" : 2
         },
         "meta" : null,
         "links" : {
            "self" : "/users/2"
         },
         "id" : "2"
      }
   ],
   "meta" : {
      "user-count" : 2
   },
   "links" : {
      "self" : "/users"
   }
}
```


## Singleton Resource Example

```JSON
GET /users/1

{
   "meta" : null,
   "data" : {
      "id" : "1",
      "attributes" : {
         "userFirstName" : "Isaac",
         "userId" : 1,
         "userLastName" : "Newton"
      },
      "meta" : null,
      "links" : {
         "self" : "/users/1"
      },
      "type" : "User",
      "relationships" : {
         "email" : {
            "links" : {
               "self" : "/emails/42"
            },
            "data" : {
               "id" : "42",
               "type" : "Email"
            }
         }
      }
   },
   "links" : {
      "self" : "/users/1"
   }
}
```


## Error Example

```JSON
GET /users/3

{
  "error":{
    "status":"404",
    "code":null,
    "id":null,
    "meta":null,
    "title":"Resource Not Found",
    "links":null,
    "detail":"There is no User with id: 3"
  },
  "meta":null,
  "links":{
    "self":"/users/3"
  }
}
```