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
You might also like...
This application demonstrates IoTVAS device discovery and security assessment API integration with the Rapid7 InsightVM.
This application demonstrates IoTVAS device discovery and security assessment API integration with the Rapid7 InsightVM.

Introduction This repository hosts a sample application that demonstrates integrating Firmalyzer's IoTVAS API with the Rapid7 InsightVM platform. This

A simple API to upload notes or files to KBFS

This API can be used to upload either secure notes or files to a secure KeybaseFS folder.

OpenSea NFT API App using Python and Streamlit

opensea-nft-api-tutorial OpenSea NFT API App using Python and Streamlit Tutorial Video Walkthrough https://www.youtube.com/watch?v=49SupvcFC1M Instruc

A tool for light-duty persistent memoization of API calls

JSON Memoize What is this? json_memoize is a straightforward tool for light-duty persistent memoization, created with API calls in mind. It stores the

External Network Pentest Automation using Shodan API and other tools.

Chopin External Network Pentest Automation using Shodan API and other tools. Workflow Input a file containing CIDR ranges. Converts CIDR ranges to ind

Automated GitHub profile content using the USGS API, Plotly and GitHub Actions.
Automated GitHub profile content using the USGS API, Plotly and GitHub Actions.

Top 20 Largest Earthquakes in the Past 24 Hours Location Mag Date and Time (UTC) 92 km SW of Sechura, Peru 5.2 11-05-2021 23:19:50 113 km NNE of Lobuj

Algorand Python API examples

Algorand-Py Algorand Python API examples This repo will hold example scripts to monitor activities on Algorand main net. You can: Monitor your assets

A Python wrapper for Matrix Synapse admin API

Synapse-admin-api-python A Python wrapper for Matrix Synapse admin API. Versioning This library now supports up to Synapse 1.45.0, any Admin API intro

Shell Trality API for local development.

Trality Simulator Intro This package is a work in progress. It allows local development of Trality bots in an IDE such as VS Code. The package provide

Owner
William Pedersen
18 year old software developer
William Pedersen
AIST++ API This repo contains starter code for using the AIST++ dataset.

AIST++ API This repo contains starter code for using the AIST++ dataset. To download the dataset or explore details of this dataset, please go to our

Google 260 Dec 30, 2022
Driving lessons made simpler. Custom scheduling API built with Python.

NOTE This is a mirror of a GitLab repository. Dryvo Dryvo is a unique solution for the driving lessons industry. Our aim is to save the teacher’s time

Adam Goldschmidt 595 Dec 5, 2022
API Rate Limit Decorator

ratelimit APIs are a very common way to interact with web services. As the need to consume data grows, so does the number of API calls necessary to re

Tomas Basham 574 Dec 26, 2022
Backend/API for the Mumble.dev, an open source social media application.

Welcome to the Mumble Api Repository Getting Started If you are trying to use this project for the first time, you can get up and running by following

Dennis Ivy 189 Dec 27, 2022
Some scripts for the Reverse engineered (old) api of CafeBazaar

bazz Note: This project is done and published only for educational purposes. Some scripts for the Reverse engineered (old) API of CafeBazaar. Be aware

Mohsen Tahmasebi 35 Dec 25, 2022
One Ansible Module for using LINE notify API to send notification. It can be required in the collection list.

Ansible Collection - hazel_shen.line_notify Documentation for the collection. ansible-galaxy collection install hazel_shen.line_notify --ignore-certs

Hazel Shen 4 Jul 19, 2021
Provide Prometheus url_sd compatible API Endpoint with data from Netbox

netbox-plugin-prometheus-sd Provide Prometheus http_sd compatible API Endpoint with data from Netbox. HTTP SD is a new feature in Prometheus and not a

Felix Peters 66 Dec 19, 2022
Simple Python API for the Ergo Platform Explorer

Ergo is a "Resilient Platform for Contractual Money." It is designed to be a platform for applications with the main focus to provide an efficient, se

null 7 Jul 6, 2021
Wrappers around the most common maya.cmds and maya.api use cases

Maya FunctionSet (maya_fn) A package that decompose core maya.cmds and maya.api features to a set of simple functions. Tests The recommended approach

Ryan Porter 9 Mar 12, 2022
An unofficial python API for trading on the DeGiro platform, with the ability to get real time data and historical data.

DegiroAPI An unofficial API for the trading platform Degiro written in Python with the ability to get real time data and historical data for products.

Jorrick Sleijster 5 Dec 16, 2022