Skip to content

Instantly share code, notes, and snippets.

View xXcarlos117Xx2's full-sized avatar
✏️
studying

Carlos Atanes Vences xXcarlos117Xx2

✏️
studying
View GitHub Profile
@xXcarlos117Xx2
xXcarlos117Xx2 / flux.js
Last active April 4, 2024 23:27
API Handler in flux with options and token manager
// flux.js
const getState = ({ getStore, getActions, setStore }) => {
return {
store: {},
actions: {
// API Handler
APICall: async (url, options) => {
try {
const response = await fetch(getStore().baseURL + url, options);
@xXcarlos117Xx2
xXcarlos117Xx2 / API-validations.md
Created April 18, 2024 23:51
Common validations for API handlers

Common validations for API's

In this Gist i will record all the validations that i use when building API's that may be useful in the future or maybe improved.

Check all the required data

response_body = {}
data = request.json
required_data = ['data1', 'data2'] # Include all the required data that the endpoint needs

for key in required_data:
@xXcarlos117Xx2
xXcarlos117Xx2 / models.py
Created July 23, 2024 18:23
Ejemplo de Backref en los modelos
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Users(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50), unique=True, nullable=False)
comments = db.relationship('Comments', backref='author', lazy=True)