SleepyFib is a REST API for producing numbers of the fibonacci sequence and returning them in JSON format.
##Requirements
SleepyFib requires the usage of the following python packages:
Flask==0.10.1 Jinja2==2.7.2 MarkupSafe==0.23 Werkzeug==0.9.4 argparse==1.2.1 distribute==0.7.3 itsdangerous==0.24 py==1.4.20 pytest==2.5.2 requests==2.2.1 wsgiref==0.1.2
This list is available in the requirements.txt file for easy installation.
For more information on Flask you can go to their main page.
##Setting Up
Setting up SleepyFib requires some knowledge of git & linux based systems.
This set up assumes you:
- Want to run this locally on your machine
- Are familiar with using virtualenv
- Are familiar with basic linux commands
This set up is a casual step by step guide to getting SleepyFib up and running. I will post links to better, more in-depth guides in each section for reference.
###Pre-Install
- Create a new virtual environment for sleepyfib
$ virtualenv sleepyfib
- Source the virtual environment so that it is running
$ source sleepyfib/bin/activate
For more information visit the virtualenv docs. Or checkout the python guide.
###Installation steps
- Clone the repository to desired location
$ git clone https://github.com/chelseawinfree/sleepyfib.git
-
Navigate to directory where you cloned SleepyFib
-
Install necessary packages
$ pip install -r requirements.txt
- Set file permissions to all and execute
$ chmod a+x app.py ## Starting up the App To start up the app, all we have to do now is launch it! Using the command ./app.py you should see the following:$ ./app.py * Running on http://127.0.0.1:5000/ * Restarting with reloaderCongratulations! It should be running. Navigate to http://localhost:5000 to make sure it is running successfully. You should see welcome message in browser.
Welcome to the SleepyFib API!...In these examples I will be using curl.
Here are a list of the calls available to you:
- [GET] To view the home index page with general information about SleepyFib
$ curl "http://localhost:5000/index" Welcome to the SleepyFib API!
- [GET] To retrieve a Fibonacci Sequence for a number that is submitted
$ curl "http://localhost:5000/sleepyfib/api/fib/5" { "The Fibonacci Sequence is": [ 0, 1, 1, 2, 3 ] }
- [GET] To retreive the limitations of the API
$ curl "http://localhost:5000/sleepyfib/api/limits" { "Limiations": [ { "description": "User should not call a number larger than 9000", "id": 1, "type": "Maximum Call Length" }, { "description": "User should only use positive integers only", "id": 2, "type": "Positive Integers Only" } ] }SleepyFib uses the wonderful pytest. To learn more about pytest read their documentation on their main page.
Make sure that your SleepyFib repo is in your PYTHONPATH! This is handled in your virtualenv activate file.
export PYTHONPATH="/path/to/sleepyfib"If you have modified it, make sure you re-activate your virtualenv to have the change!
To execute the pytests you simply execute:
$ py.test ============================================================ test session starts ============================================================ platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2 collected 6 items tests/test_fib.py ...... ========================================================= 6 passed in 0.09 seconds =========================================================or for a more verbose output:
$ py.test --verbose ============================================================ test session starts ============================================================ platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2 -- /home/chelsea/aboo/bin/python collected 6 items tests/test_fib.py:12: TestFib.test_fib_one PASSED tests/test_fib.py:17: TestFib.test_fib_two PASSED tests/test_fib.py:30: TestAPI.test_fib_negative PASSED tests/test_fib.py:37: TestAPI.test_fib_decimals PASSED tests/test_fib.py:44: TestAPI.test_fib_string PASSED tests/test_fib.py:51: TestAPI.test_fib_maximum PASSED ========================================================= 6 passed in 0.10 seconds =========================================================