Hacker News new | ask | show | jobs
by loveparade 744 days ago
I like the idea and it's not specific to web development. So many times in my career I've wanted to share a schema and data types of an application across languages that need to communicate with each other. For example, a C script that generates JSON data to be read in a Python notebook into the same data types.

I'm aware that serialization frameworks like protocol buffers do this, but they usually come with a whole lot of other baggage, dependencies, hit-or-miss language support, and clunky APIs. I want something more lightweight that allows me to start developing an application by developing its schema, without it being tied to a specific serialization framework or language implementation.

3 comments

Bonus points if you can just build the tooling to work with some emerging standards at different levels of the stack. A few relevant ones that come to mind would be:

- CBOR for the on the wire format

- CDDL for schema design of CBOR objects.

- WebTransport as the API you use on top of HTTP/3 for actually moving bits of data back and forth between client and server.

The nice thing about that approach to is that it’s in no way tied of any kind of language or other architectural patterns that larger frameworks tend to force you into. The beauty of the standards process I guess.

If someone could put together a great API design experience that wrapped all of that up with cross language code generation like Protobuf / gRPC I would switch tomorrow.

Links for those (like me) who didn't recognize the acronyms:

CBOR - RFC 8949 Concise Binary Object Representation

https://www.rfc-editor.org/rfc/rfc8949.html

CDDL - RFC 8610 Concise Data Definition Language (CDDL)

https://datatracker.ietf.org/doc/html/rfc8610

Tangentially related: I needed to share some binary data from Java to python. Didn’t want to pull in protobuf (for probably mostly bad reasons), so I wrote a writer implementation in Java, then asked gpt4o to write the python reader. Worked like a charm - it produced a great starting point then refactored it to my liking.

All that to say: with chatbots being able to implement “the other side”, it really made it a lot easier to just whip up a custom schema and not really worry too much.

(Helped that it was a one off in my case, unclear how well this would scale to real world production usage)

JSONSchema is good for this IME. It can model 99.9% of usual models, supports generation & validation for most major languages. It's also part of OpenAPI, useful if you expand your modelling to REST APIs.

https://json-schema.org/implementations

how can i auto generate api code with this
You would use OpenAPI (formerly Swagger) [1] for that, which includes JSONSchema for data types but also adds specs for defining REST apis. There are plenty of generators and other tools that work with OpenAPI [2]

[1] https://www.openapis.org/

[2] https://openapi-generator.tech/