Setting up and testing endpoints (for t3 stack)

Hey y'all. Fairly new to this tech stack (and next.js in general) so forgive the potential ignorance of the question, but i haven't seemed to find any clear answers on this (or i just know too little). Anywhos, the thing i'm wondering is can i define/test "traditional" endpoints using the api/routers way, and how does that work? Eg. i would like to create a getUserById get endpoint, and a createUser endpoint, and then try calling them externally (e.g. via postman, or another website, etc.) How do you go about doing this? The reason for me wanting to do the above is i'm thinking about potentially having some api calls on the app that can be called externally from other sites. Thanks in advance!
3 Replies
.traevelliath
.traevelliath14mo ago
it's achieved through webhooks. This 'another website' should send one to the endpoint you expose spicifically for this, then based on payload or type of event you can execute logic.
digeman
digeman14mo ago
Ah I see! Alright thanks for steering me in the right direction! Will let you know how it goes. Appreciated!
Liam
Liam14mo ago
To clarify, there is sort of 2 ways to setup "endpoints" in T3 Stack: 1. Using TRPC which gives you end to end typechecked apis (EG: both the submitted body and the response are typed so you always know the shape of your data). Docs: https://create.t3.gg/en/usage/trpc 2. Using Next.js API Routes. This is very similar to making a rest API with something like express if you have done that in the past. These routes are defined by folders & files you put inside your /pages/api directory (as long as you are using the non-beta version of T3 stack). One thing I will caution you here with is when looking at docs to understand the difference between the pages and app router. App router is the new way of doing things (where all files are placed in the /app/ directory) but create t3 app does not support this yet. With that said, make sure when using the docs on next's website that it is set to pages router in the top (like in the attached image) Docs: https://nextjs.org/docs/pages/building-your-application/routing/api-routes
Want results from more Discord servers?
Add your server