howtoprofessionallysay icon indicating copy to clipboard operation
howtoprofessionallysay copied to clipboard

API or NPM Package?

Open FlorianWendelborn opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. Hi, I’m currently looking for some ideas on what I could implement as a Raycast extension and I remembered this project. Would it be possible to (ideally) provide a simple JSON API or (worse but also appreciated) an NPM package with the raw data?

Describe the solution you'd like Ideally, a simple JSON API (or json file hosted on a predictable URL) would be great

Describe alternatives you've considered An NPM package that contains the JSON would also help, but it would mean that downstream projects need to always update it manually.

Additional context N/A

FlorianWendelborn avatar Sep 11 '22 00:09 FlorianWendelborn

Hey @FlorianWendelborn, in this scenario API makes more sense rather than NPM as you suggested about downstream projects need to update for getting new content, so I would be more inclined towards an API over NPM package.

But on the same lines as you may have noticed that this app does not use any user authentication, so it can become tricky to open a non auth based API route which can lead to abuse by some people. Since I am already using Cloudflare for this, I can put the API behind the Cloudflare infra and let them handle any unwanted bot requests because introducing an API_KEY concept here does not make much sense to me in this case.

Just want to make sure I don't regret exposing public API, feel free to share your thoughts.

AkashRajpurohit avatar Sep 11 '22 07:09 AkashRajpurohit

If you cache it properly, shouldn't Cloudflare be able to scale that API basically infinitely? And serving a static text file shouldn't be a big deal unless you're hosting at home. If that's the case, maybe hosting the site on GitHub Pages or so is a better idea?

FlorianWendelborn avatar Sep 11 '22 12:09 FlorianWendelborn

Cloudflare Pages do cache the static assets, but not sure if that's the same for functions as well. I know the contents of the file are pretty much static, so having it in front of CDN should just serve the purpose, but I would have to look into the caching functions part of Cloudflare.

Also, if you want to go ahead and send an PR for this then feel free to do so, will take a look at this myself soon.

AkashRajpurohit avatar Sep 11 '22 15:09 AkashRajpurohit

@AkashRajpurohit for now, all you’d actually need is to just keep the data in a .json file and serve it just like you serve static assets. I don’t think the data will grow so large anytime soon that you’d need to introduce an actual "API" with node or a similar backend serving it anytime soon.

FlorianWendelborn avatar Sep 11 '22 16:09 FlorianWendelborn

@AkashRajpurohit basically, all that’d need to be done is

  1. make https://github.com/AkashRajpurohit/howtoprofessionallysay/blob/c3bdd4c7c786899cc8e421807f4cbab1cd3b057d/content/qna.ts a .json file
  2. serve it like a static asset (usually like public folder), ideally from a /api/v1/content.json folder or so in case you end-up actually wanting a real api for this some day
  3. If you still want to keep the type safety, you could write a simple JSON Schema for it and
  4. check it with a tool like https://www.npmjs.com/package/jsonschema in GitHub actions (I think VSCode automatically already validates JSON Schemas and yeah, they’re optional so if you don’t care about keeping it TypeSafe it’s not a requirement at all, just good practice).

I can probably help a bit with potential issues that could appear while doing this

FlorianWendelborn avatar Sep 11 '22 16:09 FlorianWendelborn

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 10 '22 18:11 stale[bot]

@stale don't

FlorianWendelborn avatar Nov 11 '22 00:11 FlorianWendelborn

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 10 '23 00:01 stale[bot]

Didn't really get the chance to get back to this, but for now I have converted the content to a JSON format, and it should be accessible directly from raw GitHub response here -> https://raw.githubusercontent.com/AkashRajpurohit/howtoprofessionallysay/main/content/qna.json

This should solve the purpose of fetching the data dynamically.

AkashRajpurohit avatar Mar 19 '23 11:03 AkashRajpurohit