Git Product home page Git Product logo

joke-api's Introduction

joke-api

Simple Python Flask application that manages jokes

Overview

Jokes are ordered in categories and stored in a SQLite database. They can have an optional ranking (from 1 for bad to 10 for good).

Requirements

For using this application, you will need:

  • Python 3
  • Flask
  • SQLite 3

Docker container

There is a Dockerfile for running this application inside a container based on Alpine Linux. To create the image, run the following command:

$ docker build -t joke_api .

This will take a couple of minutes, afterwards you should see the image:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
joke_api            latest              84572d3b8826        1 hour ago          59.8MB
...

To start a new container based on this image, execute:

$ docker run -d -p 5000:5000 joke_api
b4735f102afb6e288b0a35d17b0e63da4d6bd2652467709c5c28538088ae5d30

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                   CREATED             STATUS                PORTS                                                                                                  NAMES
b4735f102afb        joke_api                   "/bin/sh -c \"/opt/jo…"   16 seconds ago      Up 14 seconds         0.0.0.0:6000->5000/tcp                                                                                 boring_chebyshev
...

It is also possible to use shipped docker-compose file:

$ docker-compose create
$ docker-compose up
Starting joke_api ... done
Attaching to joke_api
...
joke_api    |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

API calls

There is also a pre-defined Postman collection.

Categories

Call Method Parameters Description
/api/categories GET - returns all available categories
/api/categories/<id,name> GET category ID/name returns a particular category
/api/categories POST  { "item": { "name": "<str>" } } creates a new category
/api/categories/<id> PUT,POST category ID, { "item": {"id": <int>, "name": "<str>"} } updates an existing category
/api/categories/<id> DELETE category ID removes a category

Jokes

Call Method Parameters Description
/api/jokes/<id> GET joke ID retrieves a particular joke
/api/jokes/random GET - retrieves a random joke
/api/jokes/random/<id,name> GET category ID/name retrieves a random joke from a particular category
/api/jokes/random/<id,name>/<rank> GET category ID/name retrieves a random joke from a particular category with a specific minimum ranking
/api/jokes POST { "item": { "category_id": <int>, "text": "<str>", "rank": <int> } } creates a new joke within a category
/api/jokes/<id> PUT/POST joke ID, { "item": {"newid": <int>, "category_id": <int>, "text": "<str>", "rank": <int>} } updates an existing joke
/api/jokes/<id> DELETE joke ID removes a joke

Database layout

categories

Field name Field type Description
category_id INTEGER PRIMARY KEY AUTOINCREMENT category ID
category_name TEXT NOT NULL category name

jokes

Field name Field type Description
joke_id INTEGER PRIMARY KEY AUTOINCREMENT joke ID
category_id INTEGER NOT NULL (FOREIGN KEY) category ID
joke_text TEXT NOT NULL joke
joke_rank INTEGER NULL joke ranking (1 - 10)

joke-api's People

Contributors

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