Live data from Hacker News

Show HN: REST Alternative to GraphQL and tRPC

openapistack.co

31–40 of 76 posts

Re: Show HN: REST Alternative to GraphQL and tRPC

#32
Cool to see more of these kinds of projects, nice work OP!

I'm a huge fan of this general concept, so you're definitely on the right path imo. That said, two things are jumping out at me:

- Users would still be writing OpenAPI specs/JSON Schema by hand, an incredibly annoying and tedious process (unless using a nicer DSL)

- Generation/build steps are annoying (but likely unavoidable here)

As pointed out by many other comments, an unfortunate amount of teams aren't writing OAPI specs. I personally feel this is a major mistake for anyone building an API, but that's a discussion for another day.

I've been using https://www.ts-rest.com, a similar project, for a few months now. Instead of relying on OpenAPI specs as the source, you define the "contracts" using Zod. These contracts are essentially OpenAPI specs, but Zod makes for a MUCH better DSL. I really like that...

- Real-time type checking without generator steps, both server & client-side. XHR clients like `fetch`, `react-query`, etc clients are inferred from the contract.

- The Zod contracts _can_ generate/output OpenAPI specs and Mock Service Worker mocks for testing (as needed, not required)

- (Optional) Automatic request & response validation based on Zod contract definitions, no additional code needed.

- (Node) Backend agnostic (partially, anyway: NextJS, Express, Nest and Fastify supported atm)

- Works very well with `react-hook-form` & `ZodResolver`, so e.g an invalid value on client-side shows the same error as the API would have if request were fired.

- Zod types can be used as typescript (z.infer), a wonderful way to re-use e.g model types in client-side components.

This ts-rest experience has fundamentally solidified a belief in me: One single source of truth, propagating through the system, is _the_ best way to build safely and efficiently.

I am almost ashamed to look back on the many, many projects I've worked on where APIs and client-side did not share truth. Duplication of (hand-rolled) types, error messages, etc is horrific in retrospect.

I don't want to think about the amount of bugs I've come across due to this dual (at best) truth approach.

Re: Show HN: REST Alternative to GraphQL and tRPC

#33
post #32

Cool to see more of these kinds of projects, nice work OP! I'm a huge fan of this general concept, so you're definitely on the right path imo. That said, two things are jumping out at me: - Users would still be writing OpenAPI specs/JSON Schema by hand, an incredibly annoying and tedious process (unless using a nicer DSL) - Generation/build steps are annoying (but likely unavoidable here) As pointed out by many other…

Thank you for your encouraging words and insights!

There are indeed popular DSLs and code to openapi solutions out there. Many of which are easy to plug in to the openapi-stack libraries btw!

I guess I personally always found it frustrating to try to control the generated OpenAPI output using additional tooling and ended up preferring yaml + a visualisation tool as the api design workflow. (e.g. swagger editor)

But something like https://buildwithfern.com, or using zod as substitute for json schema may indeed be worth a try as a step before emitting openapi.

Re: Show HN: REST Alternative to GraphQL and tRPC

#34
post #8

What I really like with graphql that IMO all the other spec lack is a nice human readable format. When as a team you design a new API no way I am going to write openapi spec, but I can reason in GraphQL schema. Then each side takes the contract and go implement the frontend and the backend and it just works.

There are many, many frameworks for IPC/RPC or even REST that have human-readable schemas.

GraphQL is a performance nightmare, and while it might have nice and flashy dev tooling, it's fundamentally unoptimizable without extensive development investment - something that isn't an issue with REST.

Re: Show HN: REST Alternative to GraphQL and tRPC

#35
post #17

There's no winning at this layer and every attempt is as doomed as medieval alchemists trying to transmute lead to gold. The key here is overall speed, but you can't trade the time spent learning/understanding the API contract for these crazy complicated tools. The developer still has to look at the operations and data models exposed by the API, understand them, amd plan for how to integrate them into the larger appl…

This project is precisely for devs who dislike codegen and want to just ship products fast. 1. Design your API in yaml 2. Run a mock API 3. Develop the App, iterate mock API 4. Implement backend and ship No code generation needed. Generate types if you want.

How is designing an API in YAML “fast”? Isn’t using code much, much faster for the average dev?

Re: Show HN: REST Alternative to GraphQL and tRPC

#36
post #35

Earlier quoted context omitted.

This project is precisely for devs who dislike codegen and want to just ship products fast. 1. Design your API in yaml 2. Run a mock API 3. Develop the App, iterate mock API 4. Implement backend and ship No code generation needed. Generate types if you want.

How is designing an API in YAML “fast”? Isn’t using code much, much faster for the average dev?

Speaking personally as a full stack engineer, unless the backend is completely trivial to implement I find it much faster and more efficient to write and iterate JSON schema while implementing frontend features than actually implement backend logic first.

Re: Show HN: REST Alternative to GraphQL and tRPC

#37

GraphQL is more future proof than rest. Rest is tied to HTTP forever - GraphQL can be separated, easily. Rest communicates inputs and outputs in too many ways for my liking any more: headers, paths, bodies, query params, and dare I say method. One complaint for GQL is that potentially they had a chance to standardize paging, filtering, etc... instead every schema is customized. I guess we'll have to create a new stan…

I don’t really agree GraphQL is somehow more ”future proof” because it doesn’t use as many HTTP features.

It’s not like HTTP is going to go away in a while.

I find that AsyncAPI is a nice extension of OpenAPI/REST ideas if you need to go beyond request / response.

Re: Show HN: REST Alternative to GraphQL and tRPC

#38

> While REST APIs don't generally provide the same level of control to clients as GraphQL, many times this could be seen as a benefit especially in scenarios where strict control over data access and operations is crucial. REST is more secure, cacheable, and more performant on the server side as field resolution doesn't need to happen like it does with GraphQL. I'm told it is easier to develop against on the client s…

> My coworker found a GraphQL query only about five layers deep that could tip over a service.

I find arguments like this a bit odd. That's a pretty deep query in REST as well.

I don't have extensive experience with GraphQL, but the complaints I see about it often seem like things you just shouldn't be doing anyways - or, if you do, they're going to be rough in REST as well.

Re: Show HN: REST Alternative to GraphQL and tRPC

#39
post #34
post #8

What I really like with graphql that IMO all the other spec lack is a nice human readable format. When as a team you design a new API no way I am going to write openapi spec, but I can reason in GraphQL schema. Then each side takes the contract and go implement the frontend and the backend and it just works.

There are many, many frameworks for IPC/RPC or even REST that have human-readable schemas. GraphQL is a performance nightmare, and while it might have nice and flashy dev tooling, it's fundamentally unoptimizable without extensive development investment - something that isn't an issue with REST.

Citations very much needed for REST. JsonSchema is not human readable. Some RPC yes but their support on web tech is meh (grpc-web for example is a mess).

Having written large code bases in graphql I really disagree with this statement. It is just a different mindset and I like it. It does make you think way more in terms of data and their relations instead of endpoints. Sure you might get N+1 problems but its easy to mitigate and I prefer doing that on the backend instead of the frontend doing those calls.

Re: Show HN: REST Alternative to GraphQL and tRPC

#40
post #8

What I really like with graphql that IMO all the other spec lack is a nice human readable format. When as a team you design a new API no way I am going to write openapi spec, but I can reason in GraphQL schema. Then each side takes the contract and go implement the frontend and the backend and it just works.

If you want to do that, try gRPC and Proto. But I feel like REST and OpenAPI are fine especially if you start from the backend. I think with .NET Web APIs, the story is particularly good since it has out-of-the-box tooling for OpenAPI spec generation based on your exposed endpoints and models and then the option to customize that as needed. I've recently been working with it trying to get hot reload working on the fr…

Grpc browser support is pretty bad, I still can't wrap my head around the whole grpc-web thing that looks like giant hacks.

Openapi is not human readable IMO and the point is you design the API waaaay before you write any line of code. The api should express the business needs and be a two way discussion with the frontend people.

Post reply on HN