@@ -39,9 +39,25 @@ const PutHello = httpRoute({
3939} ) ;
4040type PutHello = typeof PutHello ;
4141
42+ const GetHello = httpRoute ( {
43+ path : '/hello/{id}' ,
44+ method : 'GET' ,
45+ request : httpRequest ( {
46+ params : {
47+ id : t . string ,
48+ } ,
49+ } ) ,
50+ response : {
51+ ok : t . type ( {
52+ id : t . string ,
53+ } ) ,
54+ } ,
55+ } ) ;
56+
4257const ApiSpec = apiSpec ( {
4358 'hello.world' : {
4459 put : PutHello ,
60+ get : GetHello ,
4561 } ,
4662} ) ;
4763
@@ -76,6 +92,8 @@ const CreateHelloWorld = async (parameters: {
7692 } ) ;
7793} ;
7894
95+ const GetHelloWorld = async ( params : { id : string } ) => Response . ok ( params ) ;
96+
7997test ( 'should offer a delightful developer experience' , async ( t ) => {
8098 const app = createServer ( ApiSpec , ( app : express . Application ) => {
8199 // Configure app-level middleware
@@ -84,6 +102,7 @@ test('should offer a delightful developer experience', async (t) => {
84102 return {
85103 'hello.world' : {
86104 put : [ routeMiddleware , CreateHelloWorld ] ,
105+ get : [ GetHelloWorld ] ,
87106 } ,
88107 } ;
89108 } ) ;
@@ -105,6 +124,29 @@ test('should offer a delightful developer experience', async (t) => {
105124 t . like ( response , { message : "Who's there?" } ) ;
106125} ) ;
107126
127+ test ( 'should handle io-ts-http formatted path parameters' , async ( t ) => {
128+ const app = createServer ( ApiSpec , ( app : express . Application ) => {
129+ app . use ( express . json ( ) ) ;
130+ app . use ( appMiddleware ) ;
131+ return {
132+ 'hello.world' : {
133+ put : [ routeMiddleware , CreateHelloWorld ] ,
134+ get : [ GetHelloWorld ] ,
135+ } ,
136+ } ;
137+ } ) ;
138+
139+ const server = supertest ( app ) ;
140+ const apiClient = buildApiClient ( supertestRequestFactory ( server ) , ApiSpec ) ;
141+
142+ const response = await apiClient [ 'hello.world' ]
143+ . get ( { id : '1337' } )
144+ . decodeExpecting ( 200 )
145+ . then ( ( res ) => res . body ) ;
146+
147+ t . like ( response , { id : '1337' } ) ;
148+ } ) ;
149+
108150test ( 'should invoke app-level middleware' , async ( t ) => {
109151 const app = createServer ( ApiSpec , ( app : express . Application ) => {
110152 // Configure app-level middleware
@@ -113,6 +155,7 @@ test('should invoke app-level middleware', async (t) => {
113155 return {
114156 'hello.world' : {
115157 put : [ CreateHelloWorld ] ,
158+ get : [ GetHelloWorld ] ,
116159 } ,
117160 } ;
118161 } ) ;
@@ -135,6 +178,7 @@ test('should invoke route-level middleware', async (t) => {
135178 return {
136179 'hello.world' : {
137180 put : [ routeMiddleware , CreateHelloWorld ] ,
181+ get : [ GetHelloWorld ] ,
138182 } ,
139183 } ;
140184 } ) ;
@@ -157,6 +201,7 @@ test('should infer status code from response type', async (t) => {
157201 return {
158202 'hello.world' : {
159203 put : [ CreateHelloWorld ] ,
204+ get : [ GetHelloWorld ] ,
160205 } ,
161206 } ;
162207 } ) ;
@@ -179,6 +224,7 @@ test('should return a 400 when request fails to decode', async (t) => {
179224 return {
180225 'hello.world' : {
181226 put : [ CreateHelloWorld ] ,
227+ get : [ GetHelloWorld ] ,
182228 } ,
183229 } ;
184230 } ) ;
0 commit comments