Skip to content

khan-belal/jumble-word-api

Repository files navigation


Jumble-Word-API

An API based on FastAPI that is used to scramble words

Getting Started

This project can be deployed locally or in a containerized workflow depending on the user's preference. Instructions for both deployments are located in the installation section.

Assumptions

  • Users will be familiar with the process to deploy a local kubernetes cluster and how to deploy resources on cluster

  • All requests to api will be recorded in audit log (including request to get audit log)

Prerequisites

This project requires the software below as a prerequisite. It has been split into two sections depending on the type of deployment

Containerized deployment

  • docker desktop (required only if deploying k8s cluster using kind)

    choco install docker-desktop (windows through chocolatey)
    brew install docker (mac os through homebrew)
  • kubernetes cli (kubectl)

    choco install kubernetes-cli (windows through chocolatey)
    brew install kubernetes-cli (mac os thorugh homebrew)
  • helm (optional)

    choco install kubernetes-helm (windows through chocolatey)
    brew install helm (mac os through homebrew)
  • kubernetes cluster (local)

  • kind (requires docker desktop)

    choco install kind (windows through chocolatey)
    brew install kind (mac os though chocolatey)

or

  • minikube
    choco install minikube (windows through chocolatey)
    brew install minikube (mac os through homebrew)

Local Deployment

  • Python3

    choco install python (windows through chocolatey)
    brew install [email protected] (macos through homebrew)
  • FastAPI (requires python)

    pip install fastapi
  • Uvicorn (requires python)

    pip install "uvicorn[standard]"

Building/Updating Docker Image

  1. Clone or Download the code from the repository
git clone https://github.com/khan-belal/jumble-word-api.git
or 

Pull image from docker hub

docker pull belalkhan/jumble-word-api:latest
  1. Make required changes to Docker file/application file

  2. Build docker image

docker build -t khan-belal/jumble-word-api .
  1. Run new built image
docker run -p 80:80 khan-belal/jumble-word-api

Installation

Containerized deployment

  1. Clone or Download the code from the repository
git clone https://github.com/khan-belal/jumble-word-api.git
  1. Deploy a local kubernetes cluster.

    If using kind use the included config file to ensure networking ports are exposed for connectivity

kind create cluster --name my-cluster --config=kind-config.yaml
If using minikube, start the kubernetes cluster.
minkube start
  1. Check status of cluster and confirm kubectl has been setup correctly

    kubectl get nodes
  2. Create namespace for application

kubectl create namespace jumble-word
  1. Deploy the application

    If using helm

    helm install --namespace jumble-word jumble-word-api --values ./jumble-word-api/values.yaml

    Otherwise, kubectl can be used to deploy the app directly

    kubectl apply -f -namespace jumble-word api-deployment.yaml

Local Deployment

  1. Ensure python is installed

    python3 --version
  2. Install required packages for FastAPI/Uvicorn

pip install fastapi
pip install "uvicorn[standard]"
  1. Start the uvicorn server
uvicorn main:app

(back to top)

Usage

The api enables 2 functionalities with usage examples for each function below:

jumble-word The main function of the api is to jumble words that are supplied to the api.

To request a jumbled word from the api, first locate the ip address of the pod/instance running the api.

If running on the local machine, the address for the api will be

http://localhost:8000

If running on a local kubernetes cluster, obtain the ip address of the running node. This is especially important if running the cluster in WSL2 on Windows.

minikube ip

If using kind obtain the ip address of the linux instance running in WSL2 (windows only)

ifconfig eth0

Once the ip address of the api is located, the api can be queried using the examples below:

Jumble-word To scramble the word happy, send the request to the api using:

localhost:8000/jumble-word?word=happy

Output:

ppayh

Audit api To get an audit log of the last 10 calls made to the api, run:

localhost:8000/audit

Output:

"{\"api_call\": \"Get audit-log\", \"query\": \"N/A\", \"payload\": \"N/A\"}\n"

(back to top)

About

API based on FastAPI used to scramble words

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published