Skip to content

Instantly share code, notes, and snippets.

View joshtwist's full-sized avatar

Josh Twist joshtwist

View GitHub Profile
{
"zudoku": {
"url": "https://zudoku.dev"
},
"rate-my-openAPI" : {
"url" : "https://ratemyopenapi.com"
},
"mockbin" : {
"url" : "https://mockbin.io"
},
{
"openapi": "3.0.0",
"info": {
"title": "Pizza Ordering API",
"description": "An API to order pizzas, check order status, and view menu options",
"version": "1.0.0"
},
"paths": {
"/pizza/order": {
"post": {
{
"openapi": "3.0.0",
"info": {
"title": "Pizza Ordering API",
"description": "An API to order pizzas, check order status, and view menu options",
"version": "1.0.0"
},
"paths": {
"/pizza/order": {
"post": {
{
"openapi": "3.1.0",
"info": {
"title": "Train Travel API",
"description": "API for finding and booking train trips across Europe.\n\n## Run in Postman\n\nExperiment with this API in Postman, using our Postman Collection.\n\n[<img src=\"https://run.pstmn.io/button.svg\" alt=\"Run In Postman\" style=\"width: 128px; height: 32px;\">](https://app.getpostman.com/run-collection/9265903-7a75a0d0-b108-4436-ba54-c6139698dc08?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D9265903-7a75a0d0-b108-4436-ba54-c6139698dc08%26entityType%3Dcollection%26workspaceId%3Df507f69d-9564-419c-89a2-cb8e4c8c7b8f)\n",
"version": "1.0.0",
"contact": {
"name": "Train Support",
"url": "https://example.com/support",
"email": "[email protected]"
{
"openapi": "3.1.0",
"info": {
"title": "The Rick and Morty API (via a Zuplo Gateway)",
"version": "1.0.0",
"description": "This is an example API proxied via Zuplo. These docs are generated based on the gateway configuration. Full credit to the original and upstream API, available at rickandmortyapi.com. \n\n The source for the gateway is available on GitHub [here](https://github.com/zuplo-samples/rick-and-morty).",
"x-logo": "https://storage.googleapis.com/cdn.zuplo.com/uploads/rick-and-morty.jpeg"
},
"paths": {
"/v1/characters": {
openapi: 3.0.0
info:
title: Chill Vibes CBD Drinks API
description: >
Welcome to the Chill Vibes CBD Drinks API!
We're here to quench your thirst and soothe your soul,
one API call at a time. Remember, our drinks are high
in CBD, but our server responses are always 200 OK!
version: 1.0.0
contact:
{
"openapi": "3.0.0",
"info": {
"title": "Slice of Heaven Pizza API",
"description": "Welcome to the Slice of Heaven Pizza API! We're serving up hot, fresh endpoints faster than you can say 'extra cheese'. Whether you're looking to order a pizza, track your delivery, or browse our menu, we've got you covered. So sit back, relax, and let our API do the heavy lifting (unlike our delivery drivers, who are strictly forbidden from lifting heavy objects).",
"version": "1.0.0",
"contact": {
"name": "Pizza Support",
"email": "[email protected]",
==== Custom Roles-Based Access Control (RBAC) ==== rbac.ts
// Check user is in correct role, or return 403
if (request.user.data.roles.includes(options.role)) {
return request;
}
else {
return new Response('Access denied', { status: 403 });
}
@joshtwist
joshtwist / fire-requests.js
Created April 21, 2024 19:23
Fire async requests and summarize results in table (node)
import fetch from "node-fetch";
import ProgressBar from "progress";
// Function to handle the individual fetch operation
async function sendRequest(url, index) {
try {
// console.log(`Sending request ${index + 1} to ${url}`);
const startTime = process.hrtime(); // Start timing here
const response = await fetch(url);
const duration = process.hrtime(startTime);
@joshtwist
joshtwist / extract-query-to-context.ts
Created March 5, 2024 12:34
Extract Query String (search params) to context.custom in Zuplo
import {ZuploContext, ZuploRequest} from "@zuplo/runtime";
export default async function policy(
request: ZuploRequest,
context: ZuploContext,
options: never,
policyName: string
) {
context.custom.originalQuery = request.query;