Giter Club home page Giter Club logo

films_api's Introduction

FILMS API

descripcion

API REST en Flask utilizando las extensiones Flask-Restful y Flask-Marshmallow (basada en Marshmallow)

Extensiones a utilizar

Para crear el API, además de Flask, haremos uso de las siguientes extensiones:

  • Flask Restful: Es una extensión que permite generar APIs REST muy fácilmente. Además, viene con un montón de utilidades.
  • Flask SQLAlchemy: Para interactuar con la base de datos a través de su ORM. Puedes encontrar más información aquí.
  • Flask Migrate: Esta extensión permite generar las tablas de la base de datos a partir de ficheros de migración. Puedes encontrar más información aquí.
  • Flask Marshmallow: Es una extensión que facilita la serialización de los modelos de la base de datos a JSON y viceversa. Está basada en Marshmallow.
  • Marshmallow SQLAlchemy: Para integrar Flask Marshmallow con SQLAlchemy.

instalacion

  • crear entorno virtual (recomendado)
PS $> pip install virtualenv
PS $> python -m venv venv\
PS $> .\venv\Scripts\activate
  • instalar dependencias
PS $> pip install -r requeriments.txt 
  • crear variables de entorno
PS $> set FLASK_APP=entrypoint:app
PS $> set FLASK_ENV=development
PS $> set APP_SETTINGS_MODULE=app.config.default
  • inicializar db
PS $> flask db init
PS $> flask db migrate -m "Initial_db"
PS $> flask db upgrade

Ejecucion

PS $> flask run

pruebas

POST: http://localhost:5000/api/v1.0/films/

{
    "title": "Forrest Gump",
    "length": 8520,
    "year": 1994,
    "director": "Robert Zemeckis",
    "actors": [
        { "name": "Tom Hanks"},
        { "name": "Robin Wright"},
        { "name": "Gary Sinise"},
        { "name": "Mykelti Williamson"},
        { "name": "Sally Field"},
        { "name": "Michael Conner Humphreys"}
    ]
}

GET: http://localhost:5000/api/v1.0/films/

[
    {
        "year": 1994,
        "actors": [
            {
                "name": "Gary Sinise",
                "id": 3
            },
            {
                "name": "Michael Conner Humphreys",
                "id": 6
            },
            {
                "name": "Mykelti Williamson",
                "id": 4
            },
            {
                "name": "Robin Wright",
                "id": 2
            },
            {
                "name": "Sally Field",
                "id": 5
            },
            {
                "name": "Tom Hanks",
                "id": 1
            }
        ],
        "length": 8520,
        "id": 1,
        "director": "Robert Zemeckis",
        "title": "Forrest Gump"
    }
]

GET: http://localhost:5000/api/v1.0/films/1

{
    "year": 1994,
    "actors": [
        {
            "name": "Tom Hanks",
            "id": 1
        },
        {
            "name": "Robin Wright",
            "id": 2
        },
        {
            "name": "Gary Sinise",
            "id": 3
        },
        {
            "name": "Mykelti Williamson",
            "id": 4
        },
        {
            "name": "Sally Field",
            "id": 5
        },
        {
            "name": "Michael Conner Humphreys",
            "id": 6
        }
    ],
    "length": 8520,
    "id": 1,
    "director": "Robert Zemeckis",
    "title": "Forrest Gump"
}

films_api's People

Contributors

alainvicious avatar

Watchers

James Cloos avatar  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.