serialization

rust
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
struct Config {
    host: String,
    port: u16,

serde for zero-copy serialization and deserialization

rust serde serialization
by Marcus Chen 1 tab
php
<?php

namespace App\Http\Resources\V1;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

Versioning a Laravel API with Route Groups and Resource Transformers

laravel api versioning
by codesnips 4 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
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
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
ruby
module Paginatable
  extend ActiveSupport::Concern

  Page = Struct.new(:records, :next_cursor, keyword_init: true)

  DEFAULT_LIMIT = 25

Cursor-Paginated Rails API with ETag and Conditional GET Caching

rails api http-caching
by codesnips 3 tabs
rust
use std::io::{self, Read, Write};

pub const HEADER_LEN: usize = 8; // 4-byte length + 4-byte crc

#[derive(Debug)]
pub enum DecodeError {

Crash-Safe Write-Ahead Log With CRC-Checked Replay in Rust

wal durability crc32
by codesnips 3 tabs
typescript
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

Global ValidationPipe with class-validator DTOs and Transform in NestJS

nestjs validation dto
by codesnips 3 tabs
go
package api

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

Content-Negotiating HTTP Handler for JSON and XML in Go

go http content-negotiation
by codesnips 2 tabs
ruby
class User < ApplicationRecord
  normalizes :phone, with: ->(value) { PhoneNormalizer.call(value) }, apply_to_nil: false

  validates :phone,
            presence: true,
            uniqueness: { case_sensitive: false },

Normalizing Phone Numbers on Assignment with Rails normalizes and a Custom Serializer

rails activerecord normalization
by codesnips 3 tabs