Giter Site home page Giter Site logo

cache-it-pls's Introduction

cs50w-final-project.mov

Turn your rate-limited APIs into unlimited cached APIs through a dead-simple UI.

This is alo Aadvik's CS50w's final project!

Setup

Accquire necessary environment variables

GOOGLE_OAUTH_CALLBACK_URL = "http://localhost:8000/oauth/google/callback"

GOOGLE_OAUTH_CLIENT_ID = "your_client_id"
GOOGLE_OAUTH_CLIENT_SECRET = "your_client_secret"

To accquire these go to Google cloud console

Build the enviorment

python -m venv env
.\env\Scripts\Activate.ps1

Run the application

pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

Distinctiveness and Complexity

This service was built as a response to a problem I came across when using GitHub's highly rate-limited RestAPI, the solution to this would be to cache the responses which would require 18-20 fully-tested, bug-free lines of code AND a storage solution (Local, SQL); Cache it pls! tries to abstract away this process and spit out a single URL you can reliably call to your hearts content.

Unlike previous challenges of CS50 Web which were "web apps" this tries to be a useful, real-world micro-service to aid in building larger applications.

How it works

A chart to explain the architecture of the app

Code

The django project comprises of 3 apps, which look like so

front-end

The site is developed using bulma along with some vanilla JavaScript to glue everything together.

  • core/static/core/dashboard.js: handles the Front-End logic for /dashboard view
  • core/static/core/vendor/: holds the static files for bulma and bulma darkly theme

core

At: core/

Glues and holds the back-end logic and the UI together. It handles the following URLs

  • /index
  • /dashboard renders a SPA-ish app that holds all logic for deleting, adding jobs. See Rest API below
  • /logout

oauth

At: oauth/

The OAuth is implemented for Google only, and is a singular endpoint to both login + signup user

  • /oauth/google
  • /oauth/google/callback

Rest API

At: api/

This API is responsible for controlling the client-facing actions for a cache job. The API looks like so

POST /api/job

  • Requires authentication

Example Body

{
  url: "https://api.kanye.rest",
  time_int: 5,
  time_frame: "minutes"
}

Constraints

  • The URL must return application/json when pinged at HEADER <url> a 400 is returned otherwise
  • The time_frame must be one of minutes, hours, days a 400 is returned otherwise

DELETE /api/job/<id>

  • Requires authentication

No Body

Constraints

  • If the id is invalid, a 404 will be returned

GET /api/job/<id>

returns the last cached JSON field

No Body

cache-it-pls's People

Contributors

aadv1k avatar

Watchers

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