javascript
const express = require('express');
const { toCsv } = require('./csvSerializer');
const { fetchOrders } = require('./orderRepository');

const router = express.Router();

Content Negotiation in Express: Serve JSON or CSV From One Route

express content-negotiation rest-api
by codesnips 3 tabs
rust
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Session {
    pub user_id: u64,

Signing and Verifying Session Cookies with HMAC-SHA256 in Rust

hmac sessions cookies
by codesnips 3 tabs
typescript
import { Type } from 'class-transformer';
import { IsInt, IsOptional, IsString, Max, Min } from 'class-validator';

export class CursorPaginationQuery {
  @IsOptional()
  @IsString()

Cursor-Based Pagination for a TypeORM Repository in NestJS

nestjs typeorm pagination
by codesnips 4 tabs
java
package com.example.github;

import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

Declarative Typed HTTP Client With Retrofit and an OkHttp Auth Interceptor

retrofit okhttp http-client
by codesnips 3 tabs
php
<?php

namespace App\Providers;

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;

Per-User API Rate Limiting With a Custom RateLimiter in Laravel

laravel rate-limiting throttle
by codesnips 3 tabs
python
import asyncio
from collections import defaultdict

from fastapi import WebSocket

FastAPI WebSocket Connection Manager for Broadcasting to Room Subscribers

fastapi websockets asyncio
by codesnips 3 tabs
ruby
require 'set'
require 'json'

class Broadcaster
  def initialize
    @mutex = Mutex.new

Stream Server-Sent Events from a Sinatra Route With Keep-Alive Pings

sinatra sse streaming
by codesnips 3 tabs
go
package proxy

import (
	"log"
	"net"
	"net/http"

Building a Reverse Proxy in Go with httputil.ReverseProxy and Header Rewriting

go reverse-proxy httputil
by codesnips 3 tabs
javascript
import { useCallback, useEffect, useRef } from 'react';

export function useRafThrottle(callback) {
  const savedCallback = useRef(callback);
  const frame = useRef(null);
  const latestArgs = useRef([]);

Throttling a Scroll-Driven Reading Progress Bar with requestAnimationFrame in React

react hooks scroll
by codesnips 4 tabs
java
@Entity
@Table(name = "idempotency_records",
       uniqueConstraints = @UniqueConstraint(columnNames = "idempotency_key"))
public class IdempotencyRecord {

    public enum Status { IN_PROGRESS, COMPLETED }

Idempotent POST Handling in Spring Boot with a Stored Idempotency-Key

spring-boot idempotency rest-api
by codesnips 3 tabs
go
package domain

import "time"

type DomainEvent interface {
	EventName() string

Custom MarshalJSON for Domain Events With a Type Discriminator Envelope

go json serialization
by codesnips 3 tabs
rust
use once_cell::sync::Lazy;
use regex::Regex;
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Severity {

Grouping Log Lines by Severity and Emitting a Summary Report in Rust

logging parsing cli
by codesnips 3 tabs