I guess it's NIH for Microsoft. Oh well, at least it's TypeScript.
TypeSpec: A new language for API-centric development
111–120 of 121 posts
Re: TypeSpec: A new language for API-centric development
#112Earlier quoted context omitted.
When one starts gluing together a lot of data pipelines full of JSON trash and from all kinds of systems with incompatible data types (whether or not “lol what’s an integer?” JSON is involved), one quickly comes to appreciate why things like Protobuf exist and look the way they do.
> When one starts gluing together a lot of data pipelines full of JSON trash and from all kinds of systems with incompatible data types (whether or not “lol what’s an integer?” JSON is involved), one quickly comes to appreciate why things like Protobuf exist and look the way they do. And then one proceeds to spend days trying to mash that JSON mess into a protobuff and debugging segfaults, rather than just getting th…
Re: TypeSpec: A new language for API-centric development
#113Earlier quoted context omitted.
If you can define single spec and autogenerate everything (client/server/OpenAPI et. al.), then spec first is superior. Looking at https://smithy.io/2.0/index.html which can already generate much more than TypeSpec based on the docs and awesome list.
I'm not sure how I can autogenerate non-trivial logic, which is my point. How would you handle a typical case where based on request data an endpoint fetches some additional information from various sources and depending on that performs several different actions? This is the most common scenario I've encountered outside of extremely trivial CRUD endpoints. EDIT: don't get me wrong, I'm not being purposefully obtuse…
Coral is used by every AWS service -- every AWS service defines their APIs using Coral, and if you want to interact with another service you use a generated client.
The client can generally be used as-is, though sometimes you might want some custom client code. In the case of a generated client you can just grab the API definition of the API you want to call, generate the client in the language of your choice, and... that's it!
For the server, you still have to implement the logic of how to form the responses, but what the request/responses look like it enforced by the framework.
Here's an example: https://gist.github.com/shepherdjerred/cb041ccc2b8864276e9b1...
I'm leaving out a _lot_ of details. Coral is incredibly powerful and can do a lot of things for you for free. Smithy is, from what I can see, the same idea.
Re: TypeSpec: A new language for API-centric development
#114What is wrong with protobufs and grpc?
Re: TypeSpec: A new language for API-centric development
#115Re: TypeSpec: A new language for API-centric development
#116Re: TypeSpec: A new language for API-centric development
#117Feels like cheating, next to the yaml of openapi anything will look good. And that's all while I'm still considering openapi one of the best things that have happened. But I've also been kind of holding my breath for typescript making it's breakthrough as a schema language. More specifically its surprisingly big non-imperative, non-functional subset, obviously. And at first glance this seems to be exactly this, "what…
> next to the yaml of openapi anything will look good. Challenge accepted! https://github.com/bufbuild/protovalidate/blob/main/examples...
it's fairly concise, the method and the request/response types are well separated and readable
the only thing I could argue with is mixing validation and type defs, as it looks like one of these things that quickly evolve over time and you end up duplicating both in the schema and the business logic
Re: TypeSpec: A new language for API-centric development
#118I failed to find an answer to the main question: what output languages are supported. The only way is to emit OpenAPI and then using one of their terrible generators?
You can create your own emitters, there's info in the docs on how to do so. My team built a custom TypeSpec emitter to output a SDK and set of libraries
Re: TypeSpec: A new language for API-centric development
#119Earlier quoted context omitted.
yes, the whole world runs on nestjs
https://github.com/domaindrivendev/Swashbuckle.AspNetCore https://github.com/RicoSuter/NSwag There is no need to be facetious, solutions like these exist for many platforms and ecosystems out there. I can't possibly entertain all of them. By all means, if such similar solution does not exist for your platform, then TypeSpec could indeed be a solution for you. With best regards.
Code-first:
- No extra steps between code and running application
- No mismatch between schema and code
- Requires tooling for every language used in your stack. This tooling is usually more complex than schema-first codegen, but it is almost always built-into and core of the backend framework you are using so it tends to be better supported.
- Requires teams to know each service's backend language to propose changes
- Harder to build a coherent central API documentation if you have multiple services. Requires complex tooling for merging the different schemas from the different services
Schema first:
- Schema first means contract-first design, scales better to products with multiple separate teams using multiple languages. It is easier to learn the schema DSL than poke around backend language unknown to the developer
- Any change in the contract requires changes in two places (schema and code)
- API consumers can easily suggest changes to the schema that are implemented by the relevant team
- Usually requires some codegen step for each backend and client languages (with the usual codegen problems). Runtime-only schema validation can be done but it is usually a bad idea to rely only on it.
- Easier mocking. Clients can start implementing before backend is ready, tests can be written against mocks.
There are definitely more pros and cons that I am missing, but it is a tradeoff. I would say if you have multiple backend services and supporting multiple backend languages I would definitely go for schema-first.
You can work with OpenAPI in a schema-first way but as many people have pointed out over the years OpenAPI yaml files are, to be polite, not very human-friendly. TypeSpec seems to be a more sensible way to work with HTTP apis in a schema first way while keep interoperability with existing OpenAPI tooling at the cost of extra codegen step (typespec .tps -> openapi .yaml)
Re: TypeSpec: A new language for API-centric development
#120Earlier quoted context omitted.
New languages are at an even bigger disadvantage now with the rise of generative AI programming. A fancy new framework that is objectively better may actually be less productive because AI haven't been trained on it
There are some AI companies focusing on chatbots for developer projects that do better than using a general purpose LLM. I think this will become more common and not really a barrier