Project

apiwork

0.0
The project is in a healthy, maintained state
Define your API once — and generate everything from it
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.0
~> 3.0
~> 2.0
~> 0.9
~> 2.1

Runtime

>= 8.0
 Project Readme

Apiwork

Apiwork Apiwork

Gem Version CI License: MIT

OpenAPI TypeScript Zod

Typed APIs for Rails.

Apiwork lets you define your API once and derive validation, serialization, querying, and typed exports from the same definition.

It integrates with Rails rather than replacing it. Controllers, ActiveRecord models, and application logic remain unchanged.

See https://apiwork.dev for full documentation.


Overview

Apiwork introduces an explicit, typed boundary to a Rails application.

From a single definition, it provides:

  • Runtime request validation
  • Response serialization
  • Filtering, sorting, and pagination
  • Nested writes
  • OpenAPI specification
  • Generated TypeScript and Zod types

The same structures that validate requests in production are used to generate client artifacts. There is no parallel schema layer.


Example

A representation describes how a model appears through the API:

class InvoiceRepresentation < Apiwork::Representation::Base
  attribute :id
  attribute :number, writable: true, filterable: true, sortable: true
  attribute :status, filterable: true
  attribute :issued_on, writable: true, sortable: true

  belongs_to :customer, filterable: true
  has_many :lines, writable: true
end

Types and nullability are inferred from ActiveRecord metadata.

From this definition, Apiwork derives:

  • Typed request contracts
  • Response serializers
  • Query parameters for filtering and sorting
  • Offset or cursor-based pagination
  • Nested write handling
  • OpenAPI and client type exports

A minimal controller:

def index
  expose Invoice.all
end

def create
  expose Invoice.create(contract.body[:invoice])
end

contract.body contains validated parameters.
expose serializes the response according to the representation.


Querying

Filtering and sorting are declared on attributes and associations.

Example query parameters:

?filter[status][eq]=sent
?sort[issued_on]=desc

Operators are typed and validated. Generated client types reflect the same structure.


Standalone Contracts

Representations are optional. Contracts can be defined independently of ActiveRecord for webhooks, external APIs, or custom request and response shapes.


Installation

Add to your Gemfile:

bundle add apiwork

Then run:

rails generate apiwork:install

Status

Under active development.

License

MIT