Code Explainers

Code explainers tagged #streaming

go
func UploadChunk(c *gin.Context) {
	uploadID := c.Param("uploadID")
	if !validUploadID.MatchString(uploadID) {
		c.JSON(http.StatusBadRequest, gin.H{"error": "invalid upload id"})

Resumable chunked uploads in Gin

file-upload content-range streaming
Advanced 9 steps
rust
use axum::{
    body::Body,
    extract::Path,
    http::{header, HeaderMap, HeaderValue, StatusCode},

HTTP range requests for video streaming in Axum

http-range-requests streaming async-io
Advanced 8 steps
java
@GetMapping("/files/{id}")
public ResponseEntity<StreamingResponseBody> download(
        @PathVariable String id,
        @RequestHeader(value = HttpHeaders.RANGE, required = false) String rangeHeader) throws IOException {

HTTP range requests in Spring

http-range streaming file-io
Advanced 10 steps
python
import asyncio
import json
 
from fastapi import APIRouter, Depends, HTTPException

Streaming export progress with SSE in FastAPI

server-sent-events async-generators streaming
Advanced 8 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{header, StatusCode},

Streaming NDJSON from Postgres in Axum

streaming backpressure async
Advanced 9 steps
rust
use axum::{
    extract::State,
    response::sse::{Event, KeepAlive, Sse},
    Json,

Proxying an SSE chat stream in Axum

server-sent-events streaming async-generators
Advanced 10 steps
go
func (h *ExportHandler) BulkExport(c *gin.Context) {
	projectID := c.Param("projectID")
 
	reports, err := h.reports.ListByProject(c.Request.Context(), projectID)

Streaming a ZIP download in Gin

streaming zip-archive http-headers
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Server-Sent Events in Laravel

server-sent-events streaming long-polling
Advanced 9 steps
php
<?php
 
namespace App\Actions\Imports;
 

Streaming CSV imports with Laravel batches

lazy-collections job-batching streaming
Advanced 9 steps
python
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from starlette.status import HTTP_413_REQUEST_ENTITY_TOO_LARGE

Enforcing a max request body size in FastAPI

middleware streaming request-limits
Advanced 6 steps
javascript
const express = require('express');
const EventEmitter = require('events');
 
const router = express.Router();

Server-Sent Events with Express

server-sent-events streaming event-emitter
Advanced 8 steps
python
import json
import time
import queue
 

Server-Sent Events streaming in Flask

server-sent-events streaming pub-sub
Advanced 9 steps
java
public List<OrderSummary> streamRecentOrders(LocalDateTime since, Consumer<OrderSummary> handler) {
    String sql = """
        SELECT id, customer_id, total_cents, status, created_at
        FROM orders

Streaming large JDBC result sets safely

jdbc streaming resource-management
Intermediate 7 steps
rust
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;
 

Streaming a SHA-256 hash of a file in Rust

hashing buffered-io streaming
Intermediate 5 steps
ruby
class Admin::OrdersExportController < Admin::BaseController
  include ActionController::Live
 
  def show

Streaming a CSV export in Rails

streaming csv-export batching
Advanced 8 steps
java
@RestController
@RequestMapping("/api/reports")
public class OrderReportController {
 

Streaming a CSV export in Spring

streaming csv-export backpressure
Intermediate 9 steps
php
<?php
 
namespace App\Http\Controllers;
 

Streaming a filtered CSV export in Laravel

streaming csv-export query-builder
Intermediate 9 steps
go
func ProxyDownload(c *gin.Context) {
	objectKey := c.Param("key")
	upstream := fmt.Sprintf("%s/files/%s", storageBaseURL, objectKey)
 

Streaming a proxied download in Gin

reverse-proxy streaming http-headers
Intermediate 8 steps