Parsley is a small sample of how to build an API using Django Rest Framework.
Built with
Request:
http://localhost:8000/patients/
Response:
[
{
"url": "http://localhost:8000/patients/1/",
"first_name": "Radric",
"middle_name": "Delantic",
"last_name": "Davis",
"phones": [
{
"type": "mobile",
"number": "5554443333"
},
{
"type": "office",
"number": "1112223333"
}
],
"email": "guwop@fakehost.test",
"dob": "1980-02-12",
"age": 37,
"gender": "male",
"status": "active",
"terms_accepted": true,
"terms_accepted_at": "2018-02-01T16:53:53.610314Z",
"address": {
"line_1": "123 Main St",
"line_2": "Apt 10",
"city": "Atlanta",
"state": "GA",
"zip": "30363"
}
}
]
Request:
http://localhost:8000/patients/
Body:
{
"first_name": "Radric",
"middle_name": "Delantic",
"last_name": "Davis",
"phones": [
{
"type": "mobile",
"number": "5554443333"
},
{
"type": "office",
"number": "1112223333"
}
],
"email": "guwop@fakehost.test",
"dob": "1980-02-12",
"age": 37,
"gender": "male",
"status": "active",
"terms_accepted": true,
"terms_accepted_at": "2018-02-01T16:53:53.610314Z",
"address": {
"line_1": "123 Main St",
"line_2": "Apt 10",
"city": "Atlanta",
"state": "GA",
"zip": "30363"
}
}
Response:
{
"url": "http://localhost:8000/patients/1/",
"first_name": "Radric",
"middle_name": "Delantic",
"last_name": "Davis",
"phones": [
{
"type": "mobile",
"number": "5554443333"
},
{
"type": "office",
"number": "1112223333"
}
],
"email": "guwop@fakehost.test",
"dob": "1980-02-12",
"age": 37,
"gender": "male",
"status": "active",
"terms_accepted": true,
"terms_accepted_at": "2018-02-01T16:53:53.610314Z",
"address": {
"line_1": "123 Main St",
"line_2": "Apt 10",
"city": "Atlanta",
"state": "GA",
"zip": "30363"
}
}
Insalling is easy and FUN!
- Install Docker
- make sure docker is running
- Clone this Repo
- SSH:
git clone git@github.com:CoreyTrombley/parsley.git
- HTTPS:
git clone https://github.com/CoreyTrombley/parsley.git
- Run
docker-compose --build
- this will download and start everything you need
NOTE: On initial build the migrations will most likely try to fire before the DB is created, why i'm not sure, but you can simply just kill the compose by running
docker-compose down
in a different terminal window or usingcontrol+c
in the same terminal and restart.
- Restart if needed due to migrations failing
Returns json data about a the newly created patient.
-
URL
/patients/
-
Method:
POST
-
URL Params
None
-
Data Params
- Body
Content:
{ "first_name": "Radric", "middle_name": "Delantic", "last_name": "Davis", "phones": [ { "type": "mobile", "number": "5554443333" }, { "type": "office", "number": "1112223333" } ], "email": "guwop@fakehost.test", "dob": "1980-02-12", "age": 37, "gender": "male", "status": "active", "terms_accepted": true, "terms_accepted_at": "2018-02-01T16:53:53.610314Z", "address": { "line_1": "123 Main St", "line_2": "Apt 10", "city": "Atlanta", "state": "GA", "zip": "30363" } }
- Body
-
Success Response:
- Code: 200
Content:{ "url": "http://localhost:8000/patients/1/", "first_name": "Radric", "middle_name": "Delantic", "last_name": "Davis", "phones": [ { "type": "mobile", "number": "5554443333" }, { "type": "office", "number": "1112223333" } ], "email": "guwop@fakehost.test", "dob": "1980-02-12", "age": 37, "gender": "male", "status": "active", "terms_accepted": true, "terms_accepted_at": "2018-02-01T16:53:53.610314Z", "address": { "line_1": "123 Main St", "line_2": "Apt 10", "city": "Atlanta", "state": "GA", "zip": "30363" } }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "detail": "Not found." }
- Code: 404 NOT FOUND
-
Sample Call:
fetch('/patients/', { dataType: "json", method: "POST", body: body, }) .then(resp => resp.json()) .then(json => console.log(json));
Returns json data about a list of patients.
-
URL
/patients/
-
Method:
GET
-
URL Params
None
-
Data Params
None
-
Success Response:
- Code: 200
Content:[ { "url": "http://localhost:8000/patients/1/", "first_name": "Radric", "middle_name": "Delantic", "last_name": "Davis", "phones": [ { "type": "mobile", "number": "5554443333" }, { "type": "office", "number": "1112223333" } ], "email": "guwop@fakehost.test", "dob": "1980-02-12", "age": 37, "gender": "male", "status": "active", "terms_accepted": true, "terms_accepted_at": "2018-02-01T16:53:53.610314Z", "address": { "line_1": "123 Main St", "line_2": "Apt 10", "city": "Atlanta", "state": "GA", "zip": "30363" } } ]
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "detail": "Not found." }
- Code: 404 NOT FOUND
-
Sample Call:
fetch('/patients/', { dataType: "json", method: "GET", }) .then(resp => resp.json()) .then(json => console.log(json));
Returns json data about a single patient.
-
URL
/patients/:id
-
Method:
GET
-
URL Params
Required:
id=[integer]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "url": "http://localhost:8000/patients/1/", "first_name": "Radric", "middle_name": "Delantic", "last_name": "Davis", "phones": [ { "type": "mobile", "number": "5554443333" }, { "type": "office", "number": "1112223333" } ], "email": "guwop@fakehost.test", "dob": "1980-02-12", "age": 37, "gender": "male", "status": "active", "terms_accepted": true, "terms_accepted_at": "2018-02-01T16:53:53.610314Z", "address": { "line_1": "123 Main St", "line_2": "Apt 10", "city": "Atlanta", "state": "GA", "zip": "30363" } }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "detail": "Not found." }
- Code: 404 NOT FOUND
-
Sample Call:
fetch(`/patients/${id}/`, { dataType: "json", method: "GET", }) .then(resp => resp.json()) .then(json => console.log(json));
A short snippet describing the license (MIT, Apache etc)
MIT © CoreyTrombley