Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 552 Bytes

File metadata and controls

18 lines (13 loc) · 552 Bytes

How To Model A Basic Record

Use this pattern when the wire schema is a single flat object and your F# record already matches that shape.

open CodecMapper

type Person = { Id: int; Name: string }
let makePerson id name = { Id = id; Name = name }

let codec =
    Schema.record makePerson
    |> Schema.field "id" _.Id
    |> Schema.field "name" _.Name
    |> Json.buildAndCompile

This is the smallest authored schema shape: start the record with its constructor, then map each field explicitly and finish with Json.buildAndCompile.