Skip to content

Building my first API for science! SleepyFib because this is a RESTful API that gives the user access to the great ol' Fibonacci series

Notifications You must be signed in to change notification settings

chellygel/sleepyfib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SleepyFib

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

  1. Create a new virtual environment for sleepyfib
$ virtualenv sleepyfib
  1. 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

  1. Clone the repository to desired location
$ git clone https://github.com/chelseawinfree/sleepyfib.git
  1. Navigate to directory where you cloned SleepyFib

  2. Install necessary packages

$ pip install -r requirements.txt
  1. 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 reloader

Congratulations! 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!...

Calling the API

In these examples I will be using curl.

Here are a list of the calls available to you:

  1. [GET] To view the home index page with general information about SleepyFib
$ curl "http://localhost:5000/index"
Welcome to the SleepyFib API!
  1. [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
  ]
}
  1. [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"
    }
  ]
}

Executing Unit Tests

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 =========================================================

About

Building my first API for science! SleepyFib because this is a RESTful API that gives the user access to the great ol' Fibonacci series

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages