Code Monkey home page Code Monkey logo

gilded-rose-matt-mccormick's Introduction

Gilded Rose API

Requirements

  • Python 2.7+
  • pip
  • Virtual Env

Run Instructions

  1. Create a virtual environment

    mkvirtualenv gilded-rose-matt-mccormick

  2. Install dependencies

    pip install -r requirements.txt

  3. Run API server

    python api.py

  4. Run tests

    python tests.py

Explanation

Languages/Frameworks Chosen

I went with Python for the language simply because I've been programming with it the most lately and was most comfortable setting things up quickly.
With Python, I've used both the Django and Flask frameworks. For this simple task, I went with Flask-restful because it's a microframework and I didn't need to make use of more advanced functionality. Flask-restful provides a simple way to create a RESTful API so that was a good choice for this project.

API Data

The data is returned in JSON. JSON is pretty standard for APIs so I thought it was a good choice.

GET /items

This route lists the inventory.

curl http://127.0.0.1:5000/items

Sample Response
[
  {
    "description": "Ergonomic chair",
    "id": 1,
    "name": "Chair",
    "price": 100
  },
  ...
]

POST /items/{id}/purchase

This route is where you can purchase an item. Requires authorization.

In this task, the response will always be true. Obviously, in a real application, I would want to check other things like the number of inventory in stock and whether we have the user's credit card on file or if they have enough credits to buy.

curl -X POST -H "Authorization: Token token1" http://127.0.0.1:5000/items/1/purchase

Sample Response
{
  "success": true
}

Authentication

Authentication uses the Authorization header along with a token. I went with this for ease of use and used the Flask-HTTPAuth package which provides an easy way to do authentication. Many API's will provide you with an API token so this would also be one authentication method when building an API.

gilded-rose-matt-mccormick's People

Contributors

mattmccormick 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.