Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Generate frontend API using abeye - #105

Merged
mikkeldenker merged 2 commits into
StractOrg:mainfrom
oeb25:abeye-client
Oct 2, 2023
Merged

Generate frontend API using abeye#105
mikkeldenker merged 2 commits into
StractOrg:mainfrom
oeb25:abeye-client

Conversation

@oeb25

@oeb25 oeb25 commented Sep 27, 2023

Copy link
Copy Markdown
Collaborator

Currently we use openapi-typescript to generate the schema from the OpenAPI. What openapi-typescript does is basically "reformulate" the OpenAPI into TypeScript, but it very specifically does not generate anything actually executable. What this lead to was us writing a small communication layer as well as wrappers for each of the endpoints and manual re-exports of all the necessary types.

I've surveyed the OpenAPI generation space, and have yet to find anything I've been satisfied by, so I wrote abeye. abeye is specifically designed for the needs of the stract frontend, and generates convenient wrappers for all endpoints (SSE too), and exposes all types with readable names as well as enumerations for constants such as Region.

As seen by the delta, this reduces the code by quite a bit, but also more tightly couples the frontend API and the OpenAPI spec, and by transitivity the frontend with the backend! The method names are inferred from the paths, for example:

  • "/beta/api/autosuggest" => "autosuggest"
  • "/beta/api/explore/export" => "exploreExport"
  • "/beta/api/sites/export" => "sitesExport"
  • "/beta/api/webgraph/host/ingoing" => "webgraphHostIngoing"
  • "/beta/api/webgraph/host/outgoing" => "webgraphHostOutgoing"

Regarding SSE, I've changed the content_type of those endpoints to be text/event-stream, in-line with what it actually produces, and what I've seen other frameworks done for event streams. abeye uses the content type to generate SSE wrappers for these endpoint automatically (something I've not found in any other generators)!

To install abeye run cargo install --git https://github.com/oeb25/abeye.

@oeb25
oeb25 requested a review from mikkeldenker September 27, 2023 11:49

@mikkeldenker mikkeldenker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very neat! Even though I agree it increases the coupling between the frontend and backend, it seems to be to such a small degree that this is a more than fair trade-off. I would actually argue this amount of coupling makes development across frontend and backend more coherent.

I think there is missing a prefix '/' on all the endpoint paths. When executing a search I seem to get the following error

input: 'http://0.0.0.0:3000search',
code: 'ERR_INVALID_URL'

When it's working I think we just need to add cargo install --git https://github.com/oeb25/abeye to CONTRIBUTING.md and we can merge it in

@oeb25

oeb25 commented Sep 27, 2023

Copy link
Copy Markdown
Collaborator Author

Accidentally stripped the prefix "/beta/api" of all endpoints paths, not just when determining the names of the methods, oops!

Anyways, I've updated the CONTRIBUTING.md, and included some links too.

@oeb25
oeb25 requested a review from mikkeldenker October 2, 2023 10:30
@mikkeldenker
mikkeldenker merged commit a2a3d7d into StractOrg:main Oct 2, 2023
@oeb25
oeb25 deleted the abeye-client branch October 2, 2023 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants