Build a REST API in Go

A JSON REST API for managing a book collection using only the Go standard library. The API supports full CRUD operations, uses Go 1.22 method-based routing, and includes an in-memory store protected by a mutex for concurrent access. Prerequisites Go 1.22 or later A Unix-like terminal (macOS, Linux, or WSL on Windows) curl or a similar HTTP client for manual testing No third-party packages required Step 1: Set up the project structure Create the file mkdir -p rest-api touch rest-api/.gitignore Add the code: rest-api/.gitignore bin/ *.test *.out .DS_Store *.log tmp/ Detailed breakdown bin/ excludes compiled binaries produced by the build step. *.test and *.out exclude Go test binaries and coverage output files. .DS_Store, *.log, and tmp/ cover common OS and temporary artifacts. Step 2: Initialize the Go module Create the file cd rest-api go mod init bookapi Detailed breakdown go mod init bookapi creates a go.mod file that declares the module path as bookapi. All import paths within the project use this prefix. Since the project uses only the standard library, no dependencies are added to go.mod. Step 3: Define the book model and store This file defines the Book struct and an in-memory store with thread-safe CRUD operations. ...

14 min

Build a WebSocket Chat Server in TypeScript

A real-time chat server using WebSockets, built with TypeScript and the ws library on Node.js. The server supports named users, broadcasts messages to all connected clients, tracks join/leave events, and includes a browser-based test client. Prerequisites Node.js 20 or later npm 9 or later A Unix-like terminal (macOS, Linux, or WSL on Windows) A modern web browser for the test client Step 1: Set up the project structure Create the file mkdir -p websocket-chat-server touch websocket-chat-server/.gitignore Add the code: websocket-chat-server/.gitignore node_modules/ dist/ *.js *.d.ts *.js.map !jest.config.js .DS_Store *.log tmp/ Detailed breakdown node_modules/ excludes installed dependencies, which are restored with npm install. dist/ excludes compiled TypeScript output. *.js, *.d.ts, *.js.map exclude generated JavaScript files in the source tree. The !jest.config.js exception keeps the test config if it were in JS format. .DS_Store, *.log, and tmp/ cover common OS and temporary artifacts. Step 2: Initialize the project and install dependencies Create the file cd websocket-chat-server npm init -y Install runtime and development dependencies: ...

15 min