Skip to content

Latest commit

 

History

History
117 lines (87 loc) · 4.95 KB

File metadata and controls

117 lines (87 loc) · 4.95 KB

Library Management example api

This is an example library management api based on the OpenApi 3.0 specification which can be run on the local server and tested with the help of Postman as described below.

What is Firetail?

Firetail is an open source library that you can incorporate into your api that helps secure the endpoints. It also provides authentication and prevents common malicious queries from reaching the endpoint.

For more information, click here

Other Examples

Ecommerce api
Hotel booking api
Social media api
Swagger 2.0 Petstore api
Swagger 3.0 Petstore api

Installation


Step 1: Install Python

Download and install python (3.6+) here


Step 2: Download the files

You can either download the files from Github as a zip or clone the repo to your local machine using -

git clone https://github.com/FireTail-io/python-openapi-quickstarts.git

Step 3: Install Postman

  1. You can download and use postman or use the web version in which case you have to download the postman desktop agent to be able to send api requests to your local host.
    Download and install postman here

  2. Open the postman client and import the postman imports by clicking on File -> import
    Import yaml to postman

  3. Click on folder, choose "postman_import" folder and click open
    Postman choose folder

  4. Click import with the selected files
    Postman import collection



Step 4: Install required libraries

Install the required libraries using the following command in the cli in the downloaded location.

python3 -m pip install -r requirements.txt

Usage

Run the local server

Run the file main.py or use the following command to start the local server (It runs on http://127.0.0.1:8080)

python3 main.py

Sending api requests via Postman

NOTE: Call the endpoint called 'RETURN JWT TOKEN' to generate and set an authorization token which will allow access to the other endpoints. If the token expires, simply call the endpoint again.


Once you have the local server running, you can now send requests via postman.

  • Click on collection on the left and then select the request that you would like to send. Then fill in the parameters and body as required. Postman params
  • Click send and the response will be displayed as shown. Postman body

Sample cases

Here are some examples of sending requests to the endpoints with some sample data.
All the sample cases assume that you have done the above steps to initialize the authorization token for the endpoints that may need them and that you are running the related example as a local server.
If you want to undo the changes you have made, just restart the local server.

Get all books by genre

  1. Click on the "Get all books" endpoint and use the values "horror" and "100" for book_type and limit respectively. Click send.

    get-all-books-input

  2. The response should be as shown below.

    get-all-books-output

Get all books by author

  1. Click on the "Get all books by an author" endpoint. Use the values "bob" for author, "100" for limit and then click send.

    get-all-books-by-author-input

  2. The output will be as shwon below.

    get-all-books-by-author-output

Get a book

  1. Click on "Get a single book" endpoint. Use the value 3 for the book_id and click send.

    get-book-input

  2. Response will be as shown below.

    get-book-output