# basdijkstra/rest-assured-net architecture

> Architecture diagram of the GitHub repository basdijkstra/rest-assured-net, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/basdijkstra/rest-assured-net
- Repository: https://github.com/basdijkstra/rest-assured-net

## Overview

##### Main components
- DSL/API Frontend: At the top of the stack, you have the DSL. The file Dsl.cs (in the RestAssured.Net folder) exposes the fluent API for writing tests. This is what users leverage in their test code (as demonstrated in the README usage example).
- Configuration Module: The Configuration folder (with RestAssuredConfiguration.cs) indicates that the library supports customization and configuration options.
- Request Building & Processing: In the RestAssured.Net/Request subdirectory, you find multiple folders and files:
- Builders (e.g., RequestSpecBuilder.cs, GraphQLRequestBuilder.cs) which are used to construct the request (including paths, headers, query parameters, cookies, and even GraphQL support).
- HttpRequestProcessor.cs and ExecutableRequest.cs indicate the module that actually sends the HTTP calls.
- Exceptions subfolder for handling and propagating errors during request creation and execution.
- Logging Components: Both in the core library (RestAssured.Net/Logging) and the dedicated logging within Request/Response sections. These include RequestLogger.cs, ResponseLogger.cs, and related log level components.
- Response Handling: The RestAssured.Net/Response folder covers:
- Content type handling (e.g., ContentTypeUtils.cs)
- Deserialization support (with the Deserializer, DeserializeAs, etc.)
- Logging and extraction layers (ExtractableResponse, ExtractAs, and VerifyAs) to allow for robust validation and extraction of information from responses.
- Exception handling for deserialization and extraction errors.
- Testing & Demo Application: The separate projects (RestAssured.Net.DemoService and RestAssured.Net.Tests) not only demonstrate the usage but also ensure that the library is covered by a comprehensive test suite. In tests, components like Models (BlogPost, Location, Place, User) and schema definitions (JsonSchemaDefinitions, XmlSchemaDefinitions) are used to simulate real API interactions.

##### Component Relationships & Data Flows
- The user (or test code) starts at the DSL/API Frontend, invoking methods like Given(), When(), Get(), Then(), etc.
- These DSL calls internally use the Request Builders to create a RequestSpecification.
- The RequestSpecification is then processed by the RequestSpecificationProcessor and handed off to the HttpRequestProcessor, which makes the actual HTTP call.
- As the request is processed, logging happens at two levels – both in the request phase (via RequestLogger) and again on receiving the response (via ResponseLogger).
- The response is captured as an ExtractableResponse and then deserialized using the appropriate Deserializer, based on content type detection (handled by the ContentTypeUtils and SupportedContentType components).
- Post-processing involves validation and extraction functions (VerifyAs, ExtractAs) that the user may chain in their tests.
- Any errors in request creation, execution, response extraction, or deserialization are caught and managed by their respective Exception classes.

##### Architectural Patterns & Design Principles
- Fluent Interface / DSL Pattern: The library is built to offer an easy-to-use DSL that allows developers to write expressive tests.
- Separation of Concerns: Each layer (configuration, request building, processing, logging, and response handling) is modular, ensuring that each responsibility is clearly delineated.
- Exception Handling: Specialized exceptions for different kinds of failures (either on the request or response fronts) indicate robust error management.
- Extensibility: The use of builders and segregated modules for different HTTP operations (including GraphQL, multipart, etc.) shows the design’s adaptability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% DSL Layer
    subgraph "DSL Layer"
        DSL["DSL API"]:::dsl
    end

    %% Configuration Module
    subgraph "Configuration"
        Config["Configuration Module"]:::config
    end

    %% Request Building & Processing
    subgraph "Request Building & Processing"
        ReqBuilders["Request Builders"]:::builder
        ReqSpecProc["Request Specification Processor"]:::processor
        HTTPProc["HTTP Request Processor"]:::processor
        ReqExceptions["Request Exceptions"]:::processor
    end

    %% Logging Components
    subgraph "Logging Components"
        CoreLogging["Core Logging"]:::logging
        ReqLogger["Request Logger"]:::logging
        ResLogger["Response Logger"]:::logging
    end

    %% Response Handling
    subgraph "Response Handling"
        ContentType["Content Type Handling"]:::response
        Deserializer["Deserialization Support"]:::response
        ResponseValidator["Response Extraction/Verification"]:::response
        ResExceptions["Response Exceptions"]:::response
    end

    %% Testing & Demo Application
    subgraph "Testing & Demo"
        DemoApp["Demo Application"]:::test
        TestSuite["Test Suite"]:::test
    end

    %% External API Endpoint
    ExternalAPI["External API Endpoint"]:::external

    %% Relationships / Data Flow
    DSL -->|"invokes"| ReqBuilders
    DSL -->|"configures"| Config

    ReqBuilders -->|"creates_spec"| ReqSpecProc
    ReqBuilders -->|"logs_request"| ReqLogger

    ReqSpecProc -->|"processes_request"| HTTPProc

    HTTPProc -->|"performs_HTTP_call"| ExternalAPI
    ExternalAPI -->|"returns_response"| HTTPProc
    HTTPProc -->|"logs_response"| ResLogger

    HTTPProc -->|"detects_content"| ContentType
    ContentType -->|"deserializes"| Deserializer
    Deserializer -->|"extracts_verifies"| ResponseValidator
    ResponseValidator -->|"returns_result"| DSL

    %% Exception flow (dashed lines)
    HTTPProc -.->|"catches_request_error"| ReqExceptions
    Deserializer -.->|"catches_response_error"| ResExceptions

    %% Core Logging integration
    CoreLogging --- ReqLogger
    CoreLogging --- ResLogger

    %% Testing & Demo interactions
    DemoApp -->|"demonstrates_usage"| DSL
    TestSuite -->|"tests_DSL"| DSL

    %% Styles
    classDef dsl fill:#f9c,stroke:#333,stroke-width:2px;
    classDef config fill:#fc9,stroke:#333,stroke-width:2px;
    classDef builder fill:#9f9,stroke:#333,stroke-width:2px;
    classDef processor fill:#9cf,stroke:#333,stroke-width:2px;
    classDef logging fill:#99f,stroke:#333,stroke-width:2px;
    classDef response fill:#f99,stroke:#333,stroke-width:2px;
    classDef test fill:#ccc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb,stroke:#333,stroke-width:2px;

    %% Click Events
    click DSL "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Dsl.cs"
    click Config "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Configuration/RestAssuredConfiguration.cs"
    click ReqBuilders "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Request/Builders"
    click ReqSpecProc "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Request/RequestSpecificationProcessor.cs"
    click HTTPProc "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Request/HttpRequestProcessor.cs"
    click ReqExceptions "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Request/Exceptions"
    click ReqLogger "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Request/Logging/RequestLogger.cs"
    click ResLogger "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net/Response/Logging/ResponseLogger.cs"
    click CoreLogging "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Logging"
    click ContentType "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Response/ContentType"
    click Deserializer "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Response/Deserialization"
    click ResponseValidator "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Response"
    click ResExceptions "https://github.com/basdijkstra/rest-assured-net/tree/main/RestAssured.Net/Response/Exceptions"
    click DemoApp "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net.DemoService"
    click TestSuite "https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net.Tests"
```
