@@ -5,7 +5,6 @@ import express from 'express';
5
5
import supertest from 'supertest' ;
6
6
7
7
import { ApiSpec , apiSpec , httpRequest , httpRoute , optional } from '@api-ts/io-ts-http' ;
8
- import { Response } from '@api-ts/response' ;
9
8
import { buildApiClient , supertestRequestFactory } from '@api-ts/superagent-wrapper' ;
10
9
11
10
import { createServer } from '../src' ;
@@ -24,17 +23,17 @@ const PutHello = httpRoute({
24
23
} ) ,
25
24
response : {
26
25
// TODO: create prettier names for these codecs at the io-ts-http level
27
- ok : t . type ( {
26
+ 200 : t . type ( {
28
27
message : t . string ,
29
28
appMiddlewareRan : t . boolean ,
30
29
routeMiddlewareRan : t . boolean ,
31
30
} ) ,
32
- invalidRequest : t . type ( {
31
+ 400 : t . type ( {
33
32
errors : t . string ,
34
33
} ) ,
35
- notFound : t . unknown ,
34
+ 404 : t . unknown ,
36
35
// DISCUSS: what if a response isn't listed here but shows up?
37
- internalError : t . unknown ,
36
+ 500 : t . unknown ,
38
37
} ,
39
38
} ) ;
40
39
type PutHello = typeof PutHello ;
@@ -48,7 +47,7 @@ const GetHello = httpRoute({
48
47
} ,
49
48
} ) ,
50
49
response : {
51
- ok : t . type ( {
50
+ 200 : t . type ( {
52
51
id : t . string ,
53
52
} ) ,
54
53
} ,
@@ -78,21 +77,31 @@ const CreateHelloWorld = async (parameters: {
78
77
routeMiddlewareRan ?: boolean ;
79
78
} ) => {
80
79
if ( parameters . secretCode === 0 ) {
81
- return Response . invalidRequest ( {
82
- errors : 'Please do not tell me zero! I will now explode' ,
83
- } ) ;
80
+ return {
81
+ type : 400 ,
82
+ payload : {
83
+ errors : 'Please do not tell me zero! I will now explode' ,
84
+ } ,
85
+ } as const ;
84
86
}
85
- return Response . ok ( {
86
- message :
87
- parameters . secretCode === 42
88
- ? 'Everything you see from here is yours'
89
- : "Who's there?" ,
90
- appMiddlewareRan : parameters . appMiddlewareRan ?? false ,
91
- routeMiddlewareRan : parameters . routeMiddlewareRan ?? false ,
92
- } ) ;
87
+ return {
88
+ type : 200 ,
89
+ payload : {
90
+ message :
91
+ parameters . secretCode === 42
92
+ ? 'Everything you see from here is yours'
93
+ : "Who's there?" ,
94
+ appMiddlewareRan : parameters . appMiddlewareRan ?? false ,
95
+ routeMiddlewareRan : parameters . routeMiddlewareRan ?? false ,
96
+ } ,
97
+ } as const ;
93
98
} ;
94
99
95
- const GetHelloWorld = async ( params : { id : string } ) => Response . ok ( params ) ;
100
+ const GetHelloWorld = async ( params : { id : string } ) =>
101
+ ( {
102
+ type : 200 ,
103
+ payload : params ,
104
+ } as const ) ;
96
105
97
106
test ( 'should offer a delightful developer experience' , async ( t ) => {
98
107
const app = createServer ( ApiSpec , ( app : express . Application ) => {
0 commit comments