Next.js Discord

Discord Forum

is this a ideal API of CRUD for returning a list of Snippets? (todos, same thing)

Unanswered
Beveren posted this in #help-forum
Open in Discord
BeverenOP

15 Replies

there isn't an "ideal" API, but if you want to go the REST route, a more RESTful implementation would be

* create a new snippet: POST /snippets
* read a snippet: GET /snippets/:id
* update a snippet: PUT/PATCH /snippets/:id
* delete a snippet: DELETE /snippets/:id

so only two files:
pages/api/
  snippets/
    index.tsx
    [id].tsx
Sun bear
this video is awesome for apis: https://www.youtube.com/watch?v=CVBpYfPKGlE
BeverenOP
Do you like Neon DB and Drizzle? I’m finding it to be an absolute joke. 10 extra steps
Sun bear
It may look like a joke but it's a one time setup, and you actually own your data.

The 10 step process is actually 3 steps:
- Setting up the drizzle.config.ts (like tsconfig.json)
- Setting up schema file (You define your database here)
- Setting up database client
- Optional: adding scripts to package.json for: db:generate, db:migrate, db:studio and db:drop

Drizzle has an AI in their docs that can simply explain each of these steps. The implementation of them should not last more than 10 minutes.

It's worth learning. If you learn SQL with Drizzle and already know front-end dev, you can build any application you want.
I would have to say like TypeScript or TailwindCSS at first the setup is a nightmare and learning the new syntax is boring and unproductive, but after getting comfortable with it you start seeing the benefits and cannot imagine writing code in any other way.
BeverenOP
I was told I need to look into querying data better.
Sun bear
What do you mean?
BeverenOP
For CRUD, get familiar with queries
BeverenOP
Is this ideal for a structure?
Sun bear
well there is no ideal structure, the only thing that really matters is consistancy. i would also like to recommend you to put actions into the src folder.
schema should probably also be in the db folder
since it belongs to database logic
BeverenOP
Thank you for your help,,, i keep getting the error of
 '@vercel/postgres' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^
BeverenOP
Still haven’t resolved that