Skip to content

Commit

Permalink
Add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kracekumar committed Mar 8, 2015
1 parent 1fe31e3 commit b8c7808
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -20,3 +20,4 @@ docs/_build
/.Python
/.cache
.coverage
*.sqlite3
1 change: 1 addition & 0 deletions examples/README.md
@@ -0,0 +1 @@
This directory contains list of apps which explains how to use schematics with Python Web Frameworks.
77 changes: 77 additions & 0 deletions examples/django/README.md
@@ -0,0 +1,77 @@
#### Linkify

`Linkify` is small app similar to `reddit/hackernews` with comments and votes features.
App demonstrates how to use `Schematics` with `Django` to create APIs.

#### Installation

- Create a new virtualenv for `python3`.
- Then `pip install -r requirements`.
- `./manage.py runserver`.
- To run tests, `./test`

#### Endpoints

- `/links` -> List all links (`GET`).
- `/links/` -> Create a link (`POST`).
- `/links/<id>/` -> Read details of a link (`GET`).
- `/links/<id>/` -> Update a link (`PATCH`).
- `/links/<id>/` -> Delete a link (`DELETE`).

#### Examples

```python
# Create a new link
In [96]: data = {'title': 'Brubeck', 'url': 'https://github.com/j2labs/brubeck', 'tags':['Web Framework', 'Python']}

In [97]: r = requests.post('http://127.0.0.1:8000/links/', json=data)

In [98]: r.status_code
Out[98]: 201

In [99]: r.json()
Out[99]:
{'id': 1,
'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
'title': 'Brubeck',
'url': 'https://github.com/j2labs/brubeck'}

# Read a link

In [105]: requests.get("http://localhost:8000/links/1/").json()
Out[105]:
{'id': 1,
'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
'title': 'Brubeck',
'url': 'https://github.com/j2labs/brubeck'}

# List all links
In [106]: requests.get("http://localhost:8000/links/").json()
Out[106]:
{'items': [{'id': 1,
'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
'title': 'Brubeck',
'url': 'https://github.com/j2labs/brubeck'}],
'total': 1}

# Update a link
In [107]: update_data = {'title': 'Django', 'url': 'https://github.com/django/django'}

In [110]: r = requests.patch("http://localhost:8000/links/1/", json=update_data)

In [111]: r.status_code
Out[111]: 202

In [112]: r.json()
Out[112]:
{'id': 1,
'tags': [{'id': 1, 'title': 'Web Framework'}, {'id': 2, 'title': 'Python'}],
'title': 'Django',
'url': 'https://github.com/django/django'}

# Delete a link
In [113]: r = requests.delete("http://localhost:8000/links/1/")

In [114]: r.status_code
Out[114]: 204
```

0 comments on commit b8c7808

Please sign in to comment.