- APIs
- APIs + Django = DRF?
- DRF = RESTful APIs?
- Representational State Transfer (REST) - [Dissertation] by Roy T. Fielding
- REST APIs must be hypertext-driven - [Blog] by Roy T. Fielding
- django-rest-framework - REST, Hypermedia & HATEOAS
- Hyperlinked APIs
- How often?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
def inorder(root): | |
if root.left is not None: | |
inorder(root.left) |
I've to design APIs, with MongoDB being used as storage.
Will be using Node/ExpressJS for now.
So ... here's my use case.
There would be a lot of attributes/fields in each MongoDB document (more than 20)
But anytime I'd fetch the document, I'd only want 2-3 fields ... based on arguments
Also, there'll be filters passed on to the back-end
Seems like a perfect use case for GraphQL
But the problem is that only a few attributes (~5-6) would be known beforehand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calculate = k => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(k**3) | |
}, 500) | |
}) | |
const gimme_val = async (k) => { | |
transformed_val = await calculate(k) | |
return transformed_val | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.air_alliances.aggregate([ | |
{ | |
$lookup: | |
{ | |
"from": "air_routes", | |
"foreignField": "airline.name", | |
"localField": "airlines", | |
"as": "route_docs" | |
} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ----------------------------------------------------------------------------------------------- ## | |
## ---------------------------------- Necessary Flask Modules ------------------------------------ ## | |
from flask import Flask, render_template, request, jsonify, make_response | |
## ----------------------------------------------------------------------------------------------- ## | |
## ----------------------------------------------------------------------------------------------- ## | |
## --------------- Initialising the flask object and registering github blueprint ---------------- ## | |
app = Flask(__name__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model dependent image size validation | |
# forms.py | |
from django import forms | |
from .models import * | |
from django.core.files.images import get_image_dimensions | |
class ValidateImageForm(forms.ModelForm): | |
class Meta: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class PositiveBigIntergerRelDbTypeMixin(models.PositiveIntegerRelDbTypeMixin): | |
def rel_db_type(self, connection): | |
if connection.features.related_fields_match_type: | |
return self.db_type(connection) | |
else: | |
return models.BigIntegerField().db_type(connection=connection) | |
class PositiveBigIntegerField(PositiveBigIntegerRelDbTypeMixin, models.BigIntegerField): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Facebook Login JavaScript Example</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<script> | |
// This is called with the results from from FB.getLoginStatus(). | |
function statusChangeCallback(response) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class ModelA(models.Model): | |
fieldA1 = models.CharField(max_length=100, unique=True) | |
fieldA2 = models.TextField(validators=[URLValidator()], blank=True, null=True) | |
fieldA3 = models.CharField(max_length=100, unique=True, null=True, blank=True) | |
field4 = models.BooleanField(default=True) | |
NewerOlder