Skip to content

Smart custom endpoint structure #2139

Answered by ardatan
TorbjornHoltmon asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @TorbjornHoltmon !
We have Yoga's HTTP hooks in the plugin system that might help you in this case;

plugins: [
 {
    onRequest({ request, url, fetchAPI, endResponse }) {
       if (url.pathname === '/my-endpoint') {
         // do something
         endResponse(
           new fetchAPI.Response(...),
         )
       }
    }
 }
]

The code above hooks into the HTTP request pipeline of Yoga. Then you can handle incoming requests differently as you wish.
Also remember this uses Fetch API
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by n1ru4l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants