Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just like author simplifies HTTP communication, you can simplify:

  --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
  
  <-- {"jsonrpc": "2.0", "result": 19, "id": 1}
...example to:

  subtract(42, 23) -> 19


How do you express the schema for the jsonrpc endpoints being served? What are valid methods and parameters?


Subset of flow would work the best.


but that's not widely implemented, while OpenAPI is

there are reasons people left flow, why do you think it is a candidate for best? Simply claiming so does nothing to further anyone's understanding


If flow adoption in js bothers you, just replace it with "subset of ts" - it'd look almost the same (it's better when it comes to things like declaring exact vs inexact object types or having cosmetic shorthand for optional type).

The bottom line is that description is terse and natural. Ie. it can be generated directly from your code and code can be generated out of it.

Instead of describing protocol (headers, status codes, http verbs, redirects, urls, params, cookies, content types etc) - you describe function signatures - the very thing that already has first class support in your programming language. An api feels like a library.

Because it uses json as serialization the data types you need to cover are very small - there are no interfaces, classes, inheritance, functions (you can't provide or return objects that define functions) - everything is pretty much composed out of type aliases and unions on 6 basic json types.

Instead of programming in yaml to describe http protocol you work with functions having json on input and output - something that is natural to your host programming language already.

Think graphql but without its nonsense restrictions on query (unions on input are fine!) or cherry picking output (calling convention that is foreign to programming languages and requires embedding dsl/dedicated query engines).

Think more like header file for remote service constraint to list of functions and notifications using json as data type.


dude, the point was that flow/ts anything out of your preferred ecosystem...

it's not going to work as a general solution because

1. nobody wants the bs out of that "ecosystem" (applies to any language specific ecosystem)

2. it's not implemented in all the other languages and therefore not portable. Who's going to write all the parsers for your "solution"?

If all you write is JS/TS, you should really try out some other languages so you get a better perspective.

This is exactly why we have standards like OpenAPI... your solution would be a single ecosystem solution.

How would one put things like authentication, examples, and response codes in their public schema under your "solution"?


GraphQL has similar type system and it is portable.


yaml & json are more portable, with codecs available in many stdlibs. You can decode directly into language types in most cases

CUE is the future I hope for


Yes, cue is awesome.


You might like this thing I'm working on then

https://youtu.be/XNBqBWO4y08




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: