Code Monkey home page Code Monkey logo

kongpluginflaskapi's Introduction

Kong Plugin For QoS (Quality Of Service) - Github Externship

Project Goal

To integrate a simple Kong Plugin with Flask API.

Technologies used

  1. Flask
  2. Kong
  3. PostgreSQL(Database)

How to run this project ?

  • Clone the repository using
    https://github.com/vishalpandeyvip/KongPluginFlaskAPI.git
  • Install requirements using pip. Please make sure that you are in project's root directory.
pip3 install -r requirements.txt
  • Create a postgresql database, an user and set password using following command.
CREATE USER kong; 
CREATE DATABASE kong OWNER kong;
ALTER USER kong WITH PASSWORD 'password';
  • change the credentials in kong.config accordingly.

  • Runserver of flask API

python3 app.py
  • Run Kong
sudo kong start -c path/to/kong.config
  • Stop kong
sudo kong stop

Routes

[GET] /: Sample Response

{
    "data": "Welcome to dictionary"
}

[GET] /<word>: It returns a json response which has meaning and details about the word provided.

[
    {
        "meanings": [
            {
                "definitions": [
                    {
                        "antonyms": [],
                        "definition": "used as a greeting or to begin a phone conversation.",
                        "example": "hello there, Katie!",
                        "synonyms": []
                    }
                ],
                "partOfSpeech": "exclamation"
            },
        ]
    }
}

Step by step procedure image

  1. Added Flask API services to the kong API gateway, by sending service name and url to kong system’s URL which is running at localhost:8001 Alt text

  2. Now added the route which will redirect users to our Flask service. Alt text

  3. Authentication key plugin api-key added, It must be supplied in the header of the request by the users for a successful redirection. Alt text

  4. In case the authentication key is not supplied in the request and if these APIs are called then they will raise errors. Alt text

  5. If wrong authentication key is provided , then this error will be raised. Alt text

  6. Created a consumer who will use our Flask API through the kong API gateway. Alt text

  7. The user has been created and its api key is retrieved and passed into the header. It will call our flask API through the endpoints exposed by Kong. And now we can use our APIs successfully. Alt text Alt text

License

MIT

kongpluginflaskapi's People

Contributors

vishalpandeynits avatar

Watchers

 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.