Module _tutorial

Module _tutorial 

Source
Expand description

§Tutorial: Getting Started with Clawspec

Welcome to the Clawspec tutorial! This guide will walk you through using Clawspec to generate OpenAPI specifications from your test code.

§Learning Path

This tutorial is organized into chapters that build upon each other:

  1. Introduction - What is Clawspec and why use it
  2. Getting Started - Setting up the client and making your first request
  3. Request Building - POST requests, path and query parameters
  4. Response Handling - Processing responses and error handling
  5. Advanced Parameters - Headers, cookies, and parameter styles
  6. OpenAPI Customization - Tags, descriptions, and metadata
  7. Redaction - Stable examples with dynamic value redaction
  8. Test Integration - Using TestClient for end-to-end testing

§Quick Example

Here’s a taste of what you’ll learn:

use clawspec_core::ApiClient;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Serialize, ToSchema)]
struct CreateUser { name: String }

#[derive(Deserialize, ToSchema)]
struct User { id: u64, name: String }

// Create a client
let mut client = ApiClient::builder()
    .with_host("api.example.com")
    .build()?;

// Make a request - schema is captured automatically
let user: User = client
    .post("/users")?
    .json(&CreateUser { name: "Alice".to_string() })?
    .await?
    .as_json()
    .await?;

// Generate OpenAPI specification
let spec = client.collected_openapi().await;
println!("{}", spec.to_pretty_json()?);

Ready to start? Head to Chapter 0: Introduction!

Modules§

chapter_0
Chapter 0: Introduction
chapter_1
Chapter 1: Getting Started
chapter_2
Chapter 2: Request Building
chapter_3
Chapter 3: Response Handling
chapter_4
Chapter 4: Advanced Parameters
chapter_5
Chapter 5: OpenAPI Customization
chapter_6
Chapter 6: Redaction
chapter_7
Chapter 7: Test Integration