diff options
| author | Tom Christie | 2014-12-08 15:51:19 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-08 15:51:19 +0000 | 
| commit | 302ec59a5c8b97b5d6be1e50e16a33df51508a81 (patch) | |
| tree | e838d159f8b04f45a28b106907fdb4fee31d38b6 /docs/tutorial/1-serialization.md | |
| parent | fd02d8266b3df2a5ed41f599eae6765631643da2 (diff) | |
| parent | f3ebac061e7b5a67afe1d9440876afa804d3995d (diff) | |
| download | django-rest-framework-302ec59a5c8b97b5d6be1e50e16a33df51508a81.tar.bz2 | |
Merge pull request #2165 from phalt/httpie-examples
Use httpie for tutorials
Diffstat (limited to 'docs/tutorial/1-serialization.md')
| -rw-r--r-- | docs/tutorial/1-serialization.md | 52 | 
1 files changed, 44 insertions, 8 deletions
| diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 3621f01b..dea43cc0 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -326,17 +326,51 @@ Quit out of the shell...  In another terminal window, we can test the server. -We can get a list of all of the snippets. - -	curl http://127.0.0.1:8000/snippets/ - -	[{"id": 1, "title": "", "code": "foo = \"bar\"\n", "linenos": false, "language": "python", "style": "friendly"}, {"id": 2, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"}] +We can test our API using using [curl][curl] or [httpie][httpie]. Httpie is a user friendly http client that's written in Python. Let's install that. + +You can install httpie using pip: + +    pip install httpie + +Finally, we can get a list of all of the snippets: + +    http http://127.0.0.1:8000/snippets/ + +    HTTP/1.1 200 OK +    ... +    [ +      { +        "id": 1, +        "title": "", +        "code": "foo = \"bar\"\n", +        "linenos": false, +        "language": "python", +        "style": "friendly" +      }, +      { +        "id": 2, +        "title": "", +        "code": "print \"hello, world\"\n", +        "linenos": false, +        "language": "python", +        "style": "friendly" +      } +    ] -Or we can get a particular snippet by referencing its id. +Or we can get a particular snippet by referencing its id: -	curl http://127.0.0.1:8000/snippets/2/ +    http http://127.0.0.1:8000/snippets/2/ -	{"id": 2, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"} +    HTTP/1.1 200 OK +    ... +    { +      "id": 2, +      "title": "", +      "code": "print \"hello, world\"\n", +      "linenos": false, +      "language": "python", +      "style": "friendly" +    }  Similarly, you can have the same json displayed by visiting these URLs in a web browser. @@ -353,3 +387,5 @@ We'll see how we can start to improve things in [part 2 of the tutorial][tut-2].  [sandbox]: http://restframework.herokuapp.com/  [virtualenv]: http://www.virtualenv.org/en/latest/index.html  [tut-2]: 2-requests-and-responses.md +[httpie]: https://github.com/jakubroztocil/httpie#installation +[curl]: http://curl.haxx.se | 
