v0.4.0
core:
BodyValuetypes the chunks of streams a serializer returns, asReadableStream<Uint8Array>orAsyncIterable<string | Uint8Array>. Other chunks already failed when the response was sent, after its headers, and are now a type error in custom codecs. (7e3354b)
core:
- A
.response()for a status the route already defines is a type error. So is a.response()status outside 200 to 299. Before, both only threw when the route was defined. (1b88943)
core:
- An error response without a string
code, such as a proxy’s error page, rejects with anErrorwhosecauseholds the response as the client received it: its status, headers, cookies and decoded body. Before, only the status was kept, in the message. (30ef141)
core:
- OpenAPI documents a defined request body as required. Before,
requestBody.requiredwas never set, so generated SDKs made every body optional. (1b88943)
core:
- OpenAPI documents array query parameters as
name[]withstyle: formandexplode: true, the way the client sends them and the server reads them. (c56f8b6)
core:
- Replace the client’s
baseUrloption withoriginandmountPath, which are both optional. A browser app served from the same origin as its routes needs no options, andmountPathis the same as the server’s. Outside browsers, a call withoutoriginrejects with aTypeError. A trailing slash oforiginis ignored, and anoriginwith a path throws aTypeErrorwhen the client is created. MigratebaseUrl: "https://api.example.com/api"toorigin: "https://api.example.com", mountPath: "/api". (81f58db)
core, server:
errorResponse()from@rest-rpc/serverandwriteErrorResponse()from@rest-rpc/server/nodesend the response of aRouteError, which clients decode as one, such as from a rate limit interceptor.
core, server:
- A
serializedBody()without acontent-typeheader is sent with the selected content type, on the client and the server. Before, the runtime chose one from the body, such astext/plain;charset=UTF-8for a string, which could contradict the route’s content type. AFormDatabody is always sent with themultipart/form-datacontent type the runtime generates with its boundary, so the default multipart codec returns it as is instead of wrapping it inserializedBody(). (7e3354b)
core, server:
- A Fetch
Responsea handler returns is sent as it is, after middleware, without response validation or codecs, on Fetch and Node. Middleware receives it as the body of the envelopenext()resolves to, with its status, headers and cookies, and the envelope’s fields are sent..response(raw())declares such a route, such as in a contract, and must be the route’s only response. OpenAPI documents it as a default response..static(new Response(...))sends a clone for every request, andrespond()rejects aResponsebody. (f86a7c5)
core, server:
- A Fetch interceptor may call
next()with another request for the matched route to read, or more than once, and receives the runtime’s arguments after the request, such as Cloudflare’senv, asargs. A Node interceptor sets headers on theServerResponsebefore callingnext().
core, server:
- Add interceptors: functions around everything an app or a client does for a request, for API key checks, logging, error reporting, metrics, retries or CORS. Pass them as
interceptorstocreateApp, typed withinterceptor()from@rest-rpc/server, or@rest-rpc/server/nodefor the NodecreateApp, and tocreateClient, typed withclientInterceptor(). They run first to last and see every response, error responses included. (81f58db)
core, server:
- Body codecs receive headers instead of a content type:
serialize(value, headers)gets the outgoing headers with the selectedcontent-type, anddeserialize(body, headers)the received ones, with lowercase names. Headers a codec returns withserializedBody()replace the handler’s and the call’s,content-typeparameters included, so a codec can add a filename tocontent-disposition. Before, a handler’s headers won over them. The client chooses a request’s format from itscontent-typewherever it is set, the call’s overadditionalHeadersoverglobalHeaders. Before, acontent-typein either was ignored and the body sent as JSON, althoughglobalHeadersmade the route’s header optional. A Node request body can be read once, and a second read rejects as on Fetch instead of returning the same body or hanging. (011d62f)
core, server:
- Content types are
content-typeheaders instead of their own concept, and a body is JSON unless that header says otherwise. A route accepts the request content types its headers schema declares and answers others with415, and the client states the content type in the call’s headers. A defined response declares its content type in its headers schema, and an inferred one sends the header passed torespond()..body()and.response()take a schema, and a stream response takessse(schema). Media type records, thecontentTypeoption ofrespond(), thecontentTypeof handler arguments, client calls and results, and theBodyContent,KnownBodyContentType,MediaTypeandResponseContentDefinitiontypes are removed. AFormDatabody is always sent asmultipart/form-data, and OpenAPI reads content types from the declaredcontent-typeheader. (0699974)
core, server:
- Make server-sent events usable behind proxies and with other data formats. The client parses event streams following the SSE spec: LF, CRLF and CR line endings, an optional space after the colon, multi-line data, persisted ids and digit-only
retryvalues. Stream responses are sent withcache-control: no-cacheby default, so proxies don’t cache or buffer them.sseFormat()and thesse: { format }option on the server and the client set the data format of events, JSON by default. The server’ssseoption also takeskeepAliveandinitialComment, whichrespond(stream, { sse })overrides per stream. (eb281e2)
core, server:
- On the client, they receive the Fetch
Requestand the called route, before the response is decoded.
core, server:
- On the server, they receive every request, including ones that match no route, except those a route completed with
.static()serves.routeis the matched route’s definition, with its path andmeta, orundefinedwhen no route matches.next()resolves with every response,RouteErrors included, and rejects only with other thrown values, such as anErrora handler throws, which the app sends asINTERNAL_SERVER_ERRORwhen nothing catches it. A Node app also sends it when its interceptors finish without a response.
core, server:
- Params, query and headers schemas accept any object input, and header values passed to
respond(),globalHeadersandadditionalHeadersaccept any value, all sent withString()as documented. Before, their inputs had to be strings, numbers or booleans, soz.coerce.number()needed<number>to compile. A promise inglobalHeadersis awaited, like the result of a provider function.ClientHeaderValueandRequestScalarare removed, andClientHeadersisRecord<string, unknown>. (8f0be69)
server:
.static()rejects arespond()result with a promise body, which is not awaited, like it rejects a promise value. (350882a)
server:
- Interceptors’
next()rejects with every error thrown after it,RouteErrors included, with the status,dataand headers they’re sent with, andNOT_FOUNDfor unmatched requests. Interceptors send errors by throwing.errorResponse()andwriteErrorResponse()take any thrown value and are what the app sends with, so an interceptor catching with them turns errors into responses for the ones before it.onError()creates an interceptor that reports errors, response bodies that fail while they stream included.createRouteHandlersandcreateCatchAllHandlertakeinterceptorstoo. (30f9ad3)
server:
- Parsed query strings are objects without a prototype, so a
__proto__[]key is an ordinary key instead of replacing the object’s prototype, and fields the query doesn’t contain read asundefinedinstead of inherited values such as an array’slength. (1b88943)
server:
- Remove the
onErrorroute option and thenotFoundoption of bothcreateApps. Report errors from an interceptor instead, wherenext()rejects with them, and send a custom response for unmatched requests from an interceptor, which receives noroutefor them. (aa81df2)
server:
- The Node adapter streams
Blobresponse bodies, such as fromfs.openAsBlob(), instead of reading each into memory, and sends their size ascontent-length. Static routes with aBlobbody stream it for each response too. (7e3354b)
server:
- The Node adapter streams
FormDataresponse bodies instead of reading each into memory, files included. They are sent without acontent-length. (7e3354b)