API Routes Handling

I'm currently delving into routes and handling them but I have problems finding how to hand the process off to a middleware like express-routers. I want to essentially just forward every request to the express-router but I currently have 2 roadblocks: 1. the route parameter seems to not allow for wildcards 2. methods don't support handling all event types Maybe I just miss something obvious or what I want to do is impossible, feel free to correct me 😄
23 Replies
24
24•2y ago
what is your reasoning behind using express-router the point of api plugin is to avoid using express you either should use the API plugin, or write your own plugin using express. Don't mix the two. I'm curious to hear why you need wildcards and all event types (which I don't get?)
Favna
Favna•2y ago
Dylan Beattie
YouTube
You Give REST a Bad Name
A parody of 'You Give Love a Bad Name' - about hypermedia APIs. No, really.
Himori
HimoriOP•2y ago
I love it 😄 mainly because I couldn't figure out how to have multiple levels to the path without having to create a new file for every possible route. like /v1/* which is handling some endpoints and then a new router for a larger subcategory /v1/utilities but I guess thats a bad aproach
24
24•2y ago
you can export multiple pieces from 1 file not necessarily a bad approach but I also have questions on why you'd want versioning on what would most likely be a private api (dashboard api)
Himori
HimoriOP•2y ago
mainly because I want to have two versions a productive and a development without having to run 2 bots
24
24•2y ago
that's a really weird thing to do IMHO but not me, so don't care I would just make 2 methods in the file that have different routes but same logic
Himori
HimoriOP•2y ago
the bot integrates with game servers which have their api updated more often. but guess I could just have a second bot
Favna
Favna•2y ago
why would you want your bot to have versioned routing though is your bot's API going to be consumed by external people?
Himori
HimoriOP•2y ago
yes
24
24•2y ago
I mean I'm hypocrite here because I do have versioning too but I also have a public API sooo
Favna
Favna•2y ago
if your API is going to be consumed by external people you shouldn't integrate it into your bot IMHO if the only reason is Discord OAUTH2 then you should make tiny API on your bot using plugin-api that is called from your other external API that is build separately
24
24•2y ago
yeah I am going down that route but I am not quite arsed yet
Himori
HimoriOP•2y ago
😄 yeah The api directly talks to some servers using rcon and some using telnet I guess I don't need that part inside the discord bot
24
24•2y ago
rcon through a discord bot 😬 hope you encrypt those passwords!!
Himori
HimoriOP•2y ago
I don't even take passwords but yeah sadly those servers don#t support encrypted passwords using rcon
24
24•2y ago
I meant storage wise rcon as a protocol doesn't support encryption
Himori
HimoriOP•2y ago
if it wouldn't be for the community they wouldn't even be accessible from the outside other than rdp but hey thanks for opening my eyes and thanks for creating sapphire, even though some parts of the documentation are missleading
24
24•2y ago
oh I didn't create sapphire if you have ideas or suggestions on certain parts of where we can improve docs, that'd be great
Favna
Favna•2y ago
That credit goes to the blue people here coolkirb
24
24•2y ago
yeah I pr'd stuff but then I broke everything don't thank me 😎
Himori
HimoriOP•2y ago
btw I previously used autocode, if you know that platform, but switched to selfhosting after they changed my 20€/m cost to 669€/m a week ago 😄
Favna
Favna•2y ago
you're the second person to switch and end up here but I've never heard of the platform before
Himori
HimoriOP•2y ago
there might be more 😄 but most don't say that
Want results from more Discord servers?
Add your server