SoapJS
  • SoapJS Framework
  • Clean Architecture
  • Quick Start
  • Components
    • Entity
    • Model
    • Repository
    • Collection
    • Mapper
    • Use Case
    • Controller
    • Route
    • RouteIO
    • Route Model
    • Router
    • Dependencies
    • Service
    • Toolset
  • Configuration
    • Introduction to Configuration Files
    • Plugin Configuration Structure Overview
    • Modifying Project Structure and Components
  • Examples
    • Simple API
    • Database Interaction Strategies
      • Using Where Conditions
      • Using QueryBuilder
      • Using Dedicated Repository Method
  • Plugins
    • Node.js
      • Soap Express
      • Soap AWS
      • Soap NestJS
      • Soap MongoDB
      • Soap Redis
      • Soap Mysql
    • Dart
      • Soap Dart
  • Troubleshooting and Support
  • Community and Contributions
  • Contact us
  • Sponsors / Partners
  • Release Notes
Powered by GitBook
On this page
  1. Components

RouteIO

RouteIO acts as a mapper, tasked with converting data from the request into input for the controller, and the controller's result into the response. Each route, if it provides or returns data, is automatically assigned a RouteIO where this data parsing should be performed. RouteIO contains two optional methods (toResponse, fromRequest), depending on whether the route expects or/and returns data.

export class GetCustomerDetailsRouteIO implemets RouteIO {
  public toResponse(output: Result<Customer>): Response {
    if (result.isFailure) {
      // decide on the status type and content
      return response.status(500).send(result.failure.error.message);
    }
    const { ... } = result.content;
    // map result content to output if needed
    return response.status(200).send({...});
  }
  
  public fromRequest(request: Request): string {
    return request.params.id;
  }
}
PreviousRouteNextRoute Model

Last updated 1 year ago