1#### Linkify
2
3`Linkify` is small app similar to `reddit/hackernews` without comments and votes features.
4App demonstrates how to use `Schematics` with `Django` to create APIs.
5
6#### Installation
7
8- Create a new virtualenv for `python3`.
9- Then `pip install -r requirements`.
10- `./manage.py runserver`.
11- To run tests, `./test`
12
13#### Endpoints
14
15- `/links` -> List all links (`GET`).
16- `/links/` -> Create a link (`POST`).
17- `/links/<id>/` -> Read details of a link (`GET`).
18- `/links/<id>/` -> Update a link (`PATCH`).
19- `/links/<id>/` -> Delete a link (`DELETE`).
20
21#### Examples
22
23```python
24# Create a new link
25In [96]: data = {'title': 'Brubeck', 'url': 'https://github.com/j2labs/brubeck', 'tags':['Web Framework', 'Python']}
26
27In [97]: r = requests.post('http://127.0.0.1:8000/links/', json=data)
28
29In [98]: r.status_code
30Out[98]: 201
31
32In [99]: r.json()
33Out[99]:
34{'id': 1,
35 'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
36 'title': 'Brubeck',
37 'url': 'https://github.com/j2labs/brubeck'}
38
39# Read a link
40
41In [105]: requests.get("http://localhost:8000/links/1/").json()
42Out[105]:
43{'id': 1,
44 'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
45 'title': 'Brubeck',
46 'url': 'https://github.com/j2labs/brubeck'}
47
48# List all links
49In [106]: requests.get("http://localhost:8000/links/").json()
50Out[106]:
51{'items': [{'id': 1,
52   'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
53   'title': 'Brubeck',
54   'url': 'https://github.com/j2labs/brubeck'}],
55   'total': 1}
56
57# Update a link
58In [107]: update_data = {'title': 'Django', 'url': 'https://github.com/django/django'}
59
60In [110]: r = requests.patch("http://localhost:8000/links/1/", json=update_data)
61
62In [111]: r.status_code
63Out[111]: 202
64
65In [112]: r.json()
66Out[112]:
67{'id': 1,
68 'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
69 'title': 'Django',
70 'url': 'https://github.com/django/django'}
71
72# Delete a link
73In [113]: r = requests.delete("http://localhost:8000/links/1/")
74
75In [114]: r.status_code
76Out[114]: 204
77```
78