codeforamerica/transitmix — pull request #16 by invisiblefunnel (2014-04-21 20:56:14+00:00)
Title: Towards a dedicated backend

Getting the discussion going around some initial code. Nothing is set in stone. Maybe someone familiar with the Backbone code can pair with me on this. For now, the `lines` table currently has two columns, `properties` and `coordinates`. Each column can store arbitrary JSON. Eventually we'll need to have dedicated columns and PostGIS types to query on, but a Parse-like backend will allow for experimentation. Some example requests:

**GET index**

All params for this action are optional. Here are the defaults:
* page=1
* per=20
* order_by=created_at
* direction=desc

```console
curl -X GET -d '{"page":2,"per":20,"order_by":"updated_at","direction":"desc"}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
http://localhost:3000/lines
```

or

```console
curl -X GET \
-H "Accept: application/json" \
'http://localhost:3000/lines?page=2&per=20&order_by=updated_at&direction=desc'
```

**POST create**
```console
curl -X POST -d '{"line":{"properties":{"name":"My Route", "color":"#AD0101"},"coordinates":[[[1.0,0.1],[2.1,1.2]]]}}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
http://localhost:3000/lines
```

**GET show**
```console
curl -X GET \
-H "Accept: application/json" \
http://localhost:3000/lines/ed50c69b-f84c-4a98-84ca-2d3a314568bf
```

**PATCH update**
```console
curl -X PATCH -d '{"line":{"coordinates":[[[3.11,11.3],[2.3,3.2]]]}}' \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
http://localhost:3000/lines/ed50c69b-f84c-4a98-84ca-2d3a314568bf
```

**DELETE destroy**
```console
curl -X DELETE \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
http://localhost:3000/lines/ed50c69b-f84c-4a98-84ca-2d3a314568bf
```

Note: There are a number of ways to indicate to Rails that you want a JSON response. Use whatever makes the most sense.
* `Accept: application/json` header
* `http://localhost:3000/lines/ed50c69b-f84c-4a98-84ca-2d3a314568bf.json`
* `http://localhost:3000/lines/ed50c69b-f84c-4a98-84ca-2d3a314568bf?format=json`