Code Explainers

Code explainers tagged #json-api

ruby
class ProjectsController < ApplicationController
  before_action :set_project, only: %i[show update destroy]
 
  def create

Scoping a Rails API controller to Current.account

multitenancy strong-parameters nested-attributes
Intermediate 7 steps
ruby
module Api
  module V1
    class BaseController < ActionController::API
      rescue_from StandardError, with: :render_internal_error

Centralized API error handling in Rails

error-handling rescue-from json-api
Intermediate 7 steps
python
import logging
import traceback
 
from flask import Blueprint, jsonify, request

Centralized JSON error handling in Flask

error-handling blueprints json-api
Intermediate 5 steps
php
<?php
 
declare(strict_types=1);
 

A single-action JSON user controller in PHP

invokable-class json-api validation
Intermediate 7 steps
ruby
class ArticlesController < ApplicationController
  DEFAULT_LIMIT = 25
  MAX_LIMIT = 100
 

Cursor-based pagination in a Rails controller

pagination cursor query-building
Intermediate 7 steps
rust
use std::time::Duration;
 
use axum::{
    http::{header, HeaderValue, Method},

Configuring CORS on an Axum Router

cors middleware http-headers
Intermediate 7 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
 

Building a typed create_user handler in Axum

serde extractors sqlx
Intermediate 7 steps
go
package middleware
 
import (
	"errors"

Centralized error handling in Gin

middleware error-handling custom-errors
Intermediate 8 steps