<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
require 'swagger_helper'
RSpec.describe 'Api::V1::Posts', type: :request do
path '/api/v1/posts' do
get 'Retrieves all posts' do
tags 'Posts'
from rest_framework import routers
from rest_framework_nested import routers as nested_routers
from . import views
router = routers.DefaultRouter()
router.register(r'posts', views.PostViewSet, basename='post')
class TokenBucket {
constructor(capacity, refillRatePerSec) {
this.capacity = capacity;
this.refillRate = refillRatePerSec;
this.tokens = capacity;
this.lastRefill = Date.now();
module Types
class PostType < Types::BaseObject
field :id, ID, null: false
field :title, String, null: false
field :body, String, null: false
field :excerpt, String, null: true
from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.response import Response
from blog.models import Post
from .serializers import PostSerializer
require "securerandom"
require "digest"
class SlidingWindowLimiter
Result = Struct.new(:allowed, :count, :remaining)
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
import { initTRPC, TRPCError } from '@trpc/server';
export interface Context {
user: { id: string; role: 'user' | 'admin' } | null;
db: DatabaseClient;
}
module Api
module V1
class UsersController < ApplicationController
before_action :authenticate_user!, except: [:index, :show]
before_action :set_user, only: [:show, :update, :destroy]
package api
import (
"encoding/json"
"net/http"
)
module KeysetPaginatable
extend ActiveSupport::Concern
class_methods do
def keyset_page(cursor: nil, limit: 20, direction: :desc)
limit = limit.to_i.clamp(1, 100)