/restx-swag

Swagger enabled Flask RESTX web services template project

Primary LanguagePythonMIT LicenseMIT

REST Webservices

A Flask RESTX API with Swagger, JWT and SQLAlchemy integration

Environment

  • Setup the requisite package on OS - Refer README.ENV.md
  • Setup docker services - Refer README.ENV.md
  • Clone the current codebase git clone https://github.com/karmarv/restx-swag.git && cd restx-swag
  • Install pre-requisite packages - pip install -r requirements.txt

Services

1. App Webservice - ./src/rest/

Check the secured API instance at http://127.0.0.1:5000/api/v1

  • Swagger Descriptor (http://localhost:5000/api/v1/swagger.json)
  • Secured data access workflow using JWT authentication
    • Register a user
      curl -X 'POST' 'http://127.0.0.1:5000/api/v1/auth/register' -H 'Content-Type: application/json' -d '{ "username": "admin", "password": "Admin@123"}'
      {"id":4,"password_hash":"[Hidden]","refresh_tokens":[],"username":"admin"}
      
    • Login to obtain access token
      curl -X 'POST' 'http://127.0.0.1:5000/api/v1/auth/login' -H 'Content-Type: application/json' -d '{ "username": "admin", "password": "Admin@123" }'
      {"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjQsImV4cCI6MTcxNDk2NTM1NiwiaWF0IjoxNzE0OTI5MzU2fQ.XNJ2UHbDGsLp5QyR5-Wm61nlWXYNXov4Pfrfmph-Z9o","refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjQsImV4cCI6MTcxNzUyMTM1NiwiaWF0IjoxNzE0OTI5MzU2fQ.xQ7UYjPPEDdLY-F5V_9kQoPcohYmDMk_VSEt-0A8uy8"}
      
    • Access protected resources using token
      curl -X 'GET' 'http://127.0.0.1:5000/api/v1/auth/protected' -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjQsImV4cCI6MTcxNDk2NTM1NiwiaWF0IjoxNzE0OTI5MzU2fQ.XNJ2UHbDGsLp5QyR5-Wm61nlWXYNXov4Pfrfmph-Z9o"
      {"level":"protected","uid":4}
      
  • Swagger UI based access
    • Documentation UI for webservices

      • Swagger UI
    • Authorization: Login and obtain the Bearer token to be filled in Authorize field on right top swagger documentation

      • Auth
    • Access the protected API from the test interface

      • Auth

2. Job/Analytics Webservice - ./src/job/

Check the unsecured backend Job services at http://127.0.0.1:5001/api/v1

  • Job management services [IN-PROGRESS]

    • List all jobs: curl -X 'GET' 'http://127.0.0.1:5001/api/v1/jobs/async' -H 'accept: application/json'
      [{"id": "job11", "job": {"name": "build an API", "type": "MBSP", "data": null}}, {"id": "job22", "job": {"name": "?????", "type": "Count", "data": "http://1.bp.blogspot.com/--M8WrSToFoo/VTVRut6u-2I/AAAAAAAAB8o/dVHTtpXitSs/s1600/URL.png"}}, {"id": "task3", "job": {"name": "profit!", "type": "Count", "data": null}}]
      
  • Swagger UI based access

    • Documentation UI for Job management services
      • Swagger UI

References