API moment - LussovAPI

Overview

LussovAPI

forthebadge forthebadge
forthebadge forthebadge

TL;DR: py API container, pip install -r requirements.txt, example, main configuration

Long version:

Install Dependancies

Download file requirements.txt

requirements.txt

Flask>=2.0.2
Flask_RESTful>=0.3.9
pymongo>=3.12.1
requests>=2.26.0
...

Install pip dependancies by running the following command inside of cmd or a shell based application

cmd / shell

pip install -r requirements.txt

🎉 Congratulations!

Initialization and Setup

Create or use a previously existing file that represents your entry script.
A simple example can be found within the repository at main.py

main.py

from server import Server



def main():
    server = Server(

    )

if __name__ == '__main__':
    main()

There are several configuration options available directly from the initialization of the Server object.
These are passed to the opject as loose type parameters.

name: str = 'Server', 
 # name of the server
host: str = 'localhost', 
 # server hosting ip
port: Optional[Union[int, str]] = 5000,
 # server hosting port
config: Optional[Union[str, dict]] = 'config.json', 
 # server configuration & value store
apidir: Optional[str] = 'apis',
 # the directory in which endpoints exist

Endpoints and Hierarchy

Each endpoint represents its own API directory, similar to how classes contain functions.
For example, both the default Ping and Test endpoints represent the test API endpoint.

How does this apply within our file structure?

.
├── ...
├── apis                    # Alternatively, directory defined in apidir
│   ├── ...                 # ...
│   └── test                # API endpoint test, all endpoints inherit prefix
|   │   ├── ...                 # ...
|   │   └── ping.py                # Contains endpoints Ping and Test
└── ...

Within this example, an API endpoint from ping.py would look as follows:
http://localhost:5000/test/{endpoint}?content={}

Within the file itself, it becomes clear that these endpoints function similar to React routing, requiring functional exporting.
Endpoint: super().__init__(**kwargs) @Endpoint.RequiresArgs() def get(self, args: dict) -> tuple: print(args) return {'response' : 'Pong'}, Endpoint.Codes.OK class Test(Endpoint): def __init__(self, **kwargs) -> Endpoint: super().__init__(**kwargs) def get(self) -> tuple: return {}, Endpoint.Codes.OK """ Router """ def route() -> Optional[set]: return [ Ping, Test ] ">
...

""" 
Endpoints
"""

class Ping(Endpoint):
    def __init__(self, **kwargs) -> Endpoint:
        super().__init__(**kwargs)

    @Endpoint.RequiresArgs()
    def get(self, args: dict) -> tuple:
        print(args)

        return {'response' : 'Pong'}, Endpoint.Codes.OK

class Test(Endpoint):
    def __init__(self, **kwargs) -> Endpoint:
        super().__init__(**kwargs)

    def get(self) -> tuple:

        return {}, Endpoint.Codes.OK

"""
Router
"""

def route() -> Optional[set]:
    return [
        Ping,
        Test
    ]

Methods

Within each endpoint, there are several HTTP methods available for utilizing, such as:
get

def get(self) -> tuple:
  return {}, Endpoint.Codes.OK


post

def post(self) -> tuple:
  return {}, Endpoint.Codes.OK


put

def put(self) -> tuple:
  return {}, Endpoint.Codes.OK


delete

def delete(self) -> tuple:
  return {}, Endpoint.Codes.OK


... and more

A list of all modern HTTP methods and their descriptions can be found here

Decorators

You may also notice that there are several applicable decorators available.
Decorators are not required to maintain the functionality of the application, but are required if you wish to pass arguments to HTTP methods.

default arguments decorator

@Endpoint.RequiresArgs()
# Passes arguments from content to keyword args

Requires keyword content to be present within the query. All values passed to args should be passed through content as a string, per conventions.



That's all, folks

Bottom text
Owner
William Pedersen
18 year old software developer
William Pedersen
Better GitHub statistics images for your profile, with stats from private and public repos

Better GitHub statistics images for your profile, with stats from private and public repos

Jacob Strieb 2k Dec 30, 2022
Demo scripts for the Kubernetes Security Webinar

Kubernetes Security Webinar [in Russian] YouTube video (October 13, 2021) Authors: Artem Yushkovsky (LinkedIn, GitHub) Maxim Mosharov @ Whitespots.io

Slurm 34 Dec 06, 2022
A prototype COG-based tile server for sparse Mars datasets

Mars tiler Mars Tiler is a prototype web application that serves tiles from cloud-optimized GeoTIFFs, with an emphasis on supporting planetary dataset

Daven Quinn 3 Mar 23, 2022
tagls is a language server based on gtags.

tagls tagls is a language server based on gtags. Why I wrote it? Almost all modern editors have great support to LSP, but language servers based on se

daquexian 31 Dec 01, 2022
Broken Link Finder is a Burp Extension to detect broken links for a passive scanning domains and links.

Broken Link Finder Broken Link Finder is a Burp Extension to detect broken links for a passive scanning domains and links. Inspired by InitRoot's link

Red Section 10 Sep 11, 2021
A minimalist personal blogging system that natively supports Markdown, LaTeX, and code highlighting.

December Welcome to the December blogging system's code repository! Introduction December is a minimalist personal blogging system that natively suppo

TriNitroTofu 10 Dec 05, 2022
A play store search module

A play store search module

Fayas Noushad 5 Dec 01, 2021
Zeus is an open source flight intellingence tool which supports more than 13,000+ airlines and 250+ countries.

Zeus Zeus is an open source flight intellingence tool which supports more than 13,000+ airlines and 250+ countries. Any flight worldwide, at your fing

DeVickey 1 Oct 22, 2021
because rico hates uuid's

terrible-uuid-lambda because rico hates uuid's sub 200ms response times! Try it out here: https://api.mathisvaneetvelde.com/uuid https://api.mathisvan

Mathis Van Eetvelde 2 Feb 15, 2022
A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

Mengting Song 1 Jan 10, 2022
Jogo em redes similar ao clássico pedra papel e tesoura

Batalha Tática Tecnologias de Redes de Computadores-A-N-JOGOS DIGITAIS Professor Fabio Henrique Cabrini Alunos: Eric Henrique de Oliveira Silva - RA 1

Eric Henrique de Oliveira Silva 1 Dec 01, 2021
CountdownTimer - Countdown Timer For Python

Countdown Timer This python script asks for the user time (input) in seconds, an

Arinzechukwu Okoye 1 Jan 01, 2022
Team Curie is a group of people working together to achieve a common aim

Team Curie is a group of people working together to achieve a common aim. We are enthusiasts!.... We are setting the pace!.... We offer encouragement and motivation....And we believe TeamWork makes t

4 Aug 07, 2021
Is a polybar module that will show you your progress in Hack The Box

HTB-Status for Polybar Is a polybar module that will show you your progress in Hack The Box indicating your current rank, global rank, points and resp

bitc0de 8 Jan 14, 2022
Easytile blender - Simple Blender 2.83 addon for tiling meshes easily

easytile_blender Dead simple, barebones Blender (2.83) addon for placing meshes as tiles. Installation In Blender, go to Edit Preferences Add-ons

Sam Gibson 6 Jul 19, 2022
PyPI package for scaffolding out code for decision tree models that can learn to find relationships between the attributes of an object.

Decision Tree Writer This package allows you to train a binary classification decision tree on a list of labeled dictionaries or class instances, and

2 Apr 23, 2022
Python bilgilerimi eğlenceli bir şekilde hatırlamak ve daha da geliştirmek için The Big Book of Small Python Projects isimli bir kitap almıştım.

Python bilgilerimi eğlenceli bir şekilde hatırlamak ve daha da geliştirmek için The Big Book of Small Python Projects isimli bir kitap almıştım. Bu repo kitaptaki örnek programları çalıştığım oyun al

Burak Selim Senyurt 22 Oct 26, 2022
Stocks Trading News Alert Using Python

Stocks-Trading-News-Alert-Using-Python Ever Thought of Buying Shares of your Dream Company, When their stock price got down? But It is not possible to

Ayush Verma 3 Jul 29, 2022
The RAP community of practice includes all analysts and data scientists who are interested in adopting the working practices included in reproducible analytical pipelines (RAP) at NHS Digital.

The RAP community of practice includes all analysts and data scientists who are interested in adopting the working practices included in reproducible analytical pipelines (RAP) at NHS Digital.

NHS Digital 50 Dec 22, 2022
About Python's multithreading and GIL

About Python's multithreading and GIL

Souvik Ghosh 3 Mar 01, 2022