Skip to content

Commit fff0fc6

Browse files
WIP OpenAPI
1 parent 7914462 commit fff0fc6

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1-
# How to Interacts with the Backend API
1+
# How to Interact with the Backend API
2+
3+
If you're building a **Serious Backend™**, chances are that you're going to need an OpenAPI specification as an output for a number of reasons.
4+
5+
First is typically to generate the client TypeScript bindings. Yes, even if you're using TypeScript on the backend, this makes sense because the frontend model is typically only a subset oF the backend model and the OpenAPI interface is the boundary between front- and back-ends.
6+
7+
Second is that many platforms like [AWS API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-open-api.html) and [Google Cloud API Gateway](https://cloud.google.com/api-gateway/docs/openapi-overview) consume OpenAPI specs. If you are building an enterprise API or any sort of API where you'll want to implement an API gateway, you'll want OpenAPI. So even if your frontend is a TypeScript React, Vue, or Svelte application, it makes sense to use the OpenAPI bindings to generate the clients if an API gateway is in the system design.
8+
9+
Third is that OpenAPI can be the foundation of your externally facing APIs and documentation generation using tools like [Redocly](https://redocly.com/) and [Mintlify](https://mintlify.com/docs/api-playground/openapi/setup). If you're just building a simple, self-contained web app, then it isn't relevant. But if you're building a serious product (probably why you're using Nest.js and curious about .NET), then OpenAPI tooling is key.
10+
11+
::: info .NET OpenAPI support
12+
Depending on which style of API is used (Minimal, FastEndpoints, or Controllers), the approach to annotating files changes with C# and .NET. In this guide, we'll walk through the setup of controller APIs as these are the closest match for Nest.js.
13+
14+
Additionally, with .NET 9, Microsoft now offers first party tooling to support exporting OpenAPI specifications though the support for controllers has some gaps around the XML code comments at the moment.
15+
:::
16+
17+
## Authoring
18+
19+
🚧 WIP
20+
21+
## Generating Spec Files
22+
23+
🚧 WIP
24+
25+
## Generating Client Bindings
226

327
🚧 WIP

docs/pages/intermediate/express-vs-minimal-api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Both **Express.js** and **.NET Minimal Web APIs** provide lightweight ways to bu
44

55
**.NET Minimal Web APIs**, introduced in .NET 6, offer a streamlined way to build APIs with high performance and **built-in production-ready features** (no hunting for NPM packages!). Unlike Express, .NET Minimal APIs leverage the highly optimized ASP.NET Core pipeline, benefiting from asynchronous request handling, automatic dependency injection, and built-in middleware for logging, authentication, and rate limiting—many of which only need to be progressively enabled and configured rather than installed separately.
66

7+
::: tip
8+
For something between .NET Minimal APIs and .NET Controller APIs, check out [FastEndpoints](https://fast-endpoints.com/) which offers performance comparable to .NET Minimal APIs while offering a better way to organize endpoints into single responsibility files/classes.
9+
:::
10+
711
## Setting Up
812

913
We'll follow [this guide](https://blog.logrocket.com/how-to-set-up-node-typescript-express/) to set up Express with TypeScript

docs/pages/intro-and-motivation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ This guide aims to provide a walkthrough of just how similar these two languages
1212
Many of the code examples in this guide are actually in [the GitHub repo](https://github.com/CharlieDigital/typescript-is-like-csharp). Be sure to check it out so you can see the full examples and play around with the code yourself.
1313
:::
1414

15-
::: info
16-
This guide was inspired by the [Kotlin is Like C#](https://ttu.github.io/kotlin-is-like-csharp/) guide I came across while learning Kotlin.
15+
::: info Inspired by...
16+
This guide was inspired by the [Kotlin is Like C#](https://ttu.github.io/kotlin-is-like-csharp/) guide I came across while learning Kotlin. I liked the format and decided to take it to the next level!
1717
:::
1818

1919
## Are They *Really* Similar?
@@ -290,7 +290,7 @@ It will also accept this:
290290

291291
And now the `createCatDto` is carrying an extra `bark` property of dubious content because JavaScript doesn't care! *TypeScript's type safety means nothing at runtime.*
292292

293-
That's because the type information no longer exists at runtime and there's no enforcement of type which requires adding schema validators like [Zod](https://zod.dev/) or [Valibot](https://valibot.dev/) to actually check the incoming payload conforms to some shape. Of course we can add validations and schemas to prevent a `CreateCatDTO` from accepting a `CreateDogDTO` at runtime, but this is ***extra work.*** (In fact, you might be here exactly because you're fed up with this extra work to ensure the correctness and safety of your backend application!)
293+
That's because the type information no longer exists at runtime and there's no enforcement of type which requires adding schema validators like [Zod](https://zod.dev/) or [Valibot](https://valibot.dev/) to actually check the incoming payload conforms to some shape. Of course we can add validations and schemas to prevent a `CreateCatDto` from accepting a `CreateDogDto` at runtime, but this is ***extra work.*** (In fact, you might be here exactly because you're fed up with this extra work to ensure the correctness and safety of your backend application!)
294294

295295
::: tip If you are already using Nest.js...
296296
Then you will probably like [.NET controller web APIs](./intermediate/nest-vs-controller-api.md) which is conceptually similar with controllers, routes, middleware, and more.

0 commit comments

Comments
 (0)