json

ruby
module Api
  module V1
    class UsersController < ApplicationController
      before_action :authenticate_user!, except: [:index, :show]
      before_action :set_user, only: [:show, :update, :destroy]

RESTful API design with Rails

ruby rails api
by Sarah Mitchell 4 tabs
go
package api

import (
  "encoding/json"
  "net/http"
)

Consistent JSON responses (content-type + error envelopes)

go http json
by Leah Thompson 1 tab
rust
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CancelReason {
    pub reason: String,
    pub feedback: Option<String>,

Internally Tagged Enum JSON Serialization for a Rust Webhook API

rust serde json
by codesnips 3 tabs
sql
-- Create table with JSONB column
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  name VARCHAR(255),
  metadata JSONB DEFAULT '{}'::jsonb

PostgreSQL JSONB for flexible schema design

postgresql jsonb json
by Maria Garcia 2 tabs
java
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

import java.math.BigDecimal;

Deserialize Polymorphic JSON into a Sealed Interface Hierarchy with Jackson

jackson json deserialization
by codesnips 3 tabs
rust
use serde::Serialize;
use serde_json::Value;

#[derive(Debug, Clone, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum ChangeKind {

Diffing Two Config Snapshots Into a Typed Change List in Rust

rust serde config
by codesnips 3 tabs
go
package httpx

import (
	"net/http"
	"strconv"
)

Enforce a Maximum Request Body Size in Go HTTP Handlers with MaxBytesReader

http middleware security
by codesnips 3 tabs
go
package listing

import "encoding/base64"

func Encode(name string) string {
	return base64.RawURLEncoding.EncodeToString([]byte(name))

Cursor-Based Directory Listing API in Go with net/http

go pagination cursor
by codesnips 3 tabs
go
package config

import (
	"encoding/json"
	"fmt"
	"time"

Strict JSON Config Loading in Go with DisallowUnknownFields

go json configuration
by codesnips 3 tabs
go
package api

import (
	"encoding/json"
	"net/http"
)

Field-Level JSON Validation Errors in Go net/http Handlers

go net-http validation
by codesnips 3 tabs
go
package api

import "strings"

type Issue struct {
  Field   string `json:"field"`

JSON schema-ish validation with custom error details

go api json
by Leah Thompson 1 tab
java
@RestController
@RequestMapping("/api/orders")
public class OrderController {

    private final OrderService orderService;

Testing a Spring Boot Controller Slice with @WebMvcTest, MockMvc and a Mocked Service

spring-boot testing mockmvc
by codesnips 3 tabs