Git Product home page Git Product logo

parsley's Introduction

Parsley

Parsley is a small sample of how to build an API using Django Rest Framework.

Screenshots

root api patient api

Tech/framework used

Built with

Code Example

View Patients:

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": "[email protected]",
        "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"
        }
    }
]

Create a new patient:

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": "[email protected]",
  "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": "[email protected]",
  "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"
  }
}

Installation

Insalling is easy and FUN!

PreReqs

  • Install Docker
    • make sure docker is running

Steps:

  1. Clone this Repo
  • SSH: git clone [email protected]:CoreyTrombley/parsley.git
  • HTTPS: git clone https://github.com/CoreyTrombley/parsley.git
  1. 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 using control+c in the same terminal and restart.

  1. Restart if needed due to migrations failing

API Reference

Create Patient

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": "[email protected]",
      "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"
      }
    }
    
  • 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": "[email protected]",
        "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"
        }
      }
      
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { "detail": "Not found." }
  • Sample Call:

      fetch('/patients/', {
        dataType: "json",
        method: "POST",
        body: body,
      })
      .then(resp => resp.json())
      .then(json => console.log(json));

List Patients

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": "[email protected]",
          "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"
          }
        }
      ]
      
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { "detail": "Not found." }
  • Sample Call:

      fetch('/patients/', {
        dataType: "json",
        method: "GET",
      })
      .then(resp => resp.json())
      .then(json => console.log(json));

Show User

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": "[email protected]",
        "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"
        }
      } 
      
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { "detail": "Not found." }
  • Sample Call:

      fetch(`/patients/${id}/`, {
        dataType: "json",
        method: "GET",
      })
      .then(resp => resp.json())
      .then(json => console.log(json));

License

A short snippet describing the license (MIT, Apache etc)

MIT © CoreyTrombley

parsley's People

Contributors

coreytrombley avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.