Skip to content
basic Flask REST API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
migrations
.gitignore
README.md
__init__.py
app.py
manage.py
models.py
requirements.txt

README.md

Crossfade-API

A basic REST API to allow xfade.audio to create unique URL hashes for playlists.

Listens for POST requests to your-api-url.com/collections/new. Saves whatever JSON is posted in the body to a postgres database and returns a hashID (i.e. lkj902ad).

A GET request to your-api-url.com/collections/lkj902ad will return the JSON that was originally POSTed.

Adapted from this great Flask tutorial.

Installation

pip install -r requirements.txt

export APP_SETTINGS="config.DevelopmentConfig"

Create config.py:

import os
basedir = os.path.abspath(os.path.dirname(__file__))

class Config(object):
    DEBUG = False
    TESTING = False
    CSRF_ENABLED = True
    SECRET_KEY = 'your-secret-key-here'


class ProductionConfig(Config):
    DEBUG = False
    SQLALCHEMY_DATABASE_URI = 'postgresql:///crossfade'


class DevelopmentConfig(Config):
    DEVELOPMENT = True
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'postgresql:///crossfade'

Run it

python manage.py runserver

POST some JSON:

curl -H "Content-Type: application/json" -X POST -d '{"collection":{"one":["vid1","vid2","vid3"],"two":["vid4","vid5","vid6"]}}' http://localhost:5000/collection/new

GET JSON using a hashid:

curl -H "Content-Type: application/json" -X GET http://localhost:5000/collection/pnel5aKB

You can’t perform that action at this time.