Questions to new API Implementation

So I am currently rewriting my api endpoints in sapphire. I came acros some questions: 1. How can I define that main route "/"? how should I name that file? get.ts ? 2. Following REST I want to create get, post, put etc routes for a specific slug e.g. birthday. Do I need to create 4 separate files for this with each a different filename? this does not really look like an effective way? 3. Is there a possibility to create folders to put these 4 files in? or do they all have to be located in the routes folder? 4. In what extend can @ApplyOption still be used? 5. Its not clear to me how to recieve the body when using post
Solution:
1. Yes 2. Yes, mind we follow the structure libs like Nuxt and Next also use here 3. routes/subfolder/file, or register your own routes folder just like you would register any other custom folder for a store. Has been asked many times before, finding an example with a search for it shouldn't be too hard. 4. In every extend. They're still Pieces with options. Just different options. 5. Answered above...
Jump to solution
4 Replies
chillihero
chilliheroOP7d ago
okay so answer to 1) name it index.get.ts 3) yes, folder names are same valid as a subslug so <guild>/setting.get.ts where <guild> is the folder will work
Seren_Modz 21
Seren_Modz 217d ago
to answer question 4 and the first part of question 2: the route options allows passing an array of methods
Seren_Modz 21
Seren_Modz 217d ago
as for question 5: there is a number of methods on the request that can be used (eg. request.readBody()). all of them can be found here: https://www.sapphirejs.dev/docs/Documentation/api-plugins/@sapphire/plugin-api/classes/ApiRequest/#methods
Sapphire Framework
Class: ApiRequest | Sapphire
Defined in11
Solution
Favna
Favna6d ago
1. Yes 2. Yes, mind we follow the structure libs like Nuxt and Next also use here 3. routes/subfolder/file, or register your own routes folder just like you would register any other custom folder for a store. Has been asked many times before, finding an example with a search for it shouldn't be too hard. 4. In every extend. They're still Pieces with options. Just different options. 5. Answered above

Did you find this page helpful?