Jonathan Lahijani Posted October 4, 2023 Share Posted October 4, 2023 I need to develop a RESTful API in ProcessWire. While I haven't developed one before, I am fairly comfortable with the general idea. There are separate PHP frameworks that specialize in this, as well as specific ProcessWire modules, however I want to do this purely with ProcessWire. I haven't seen discussion on this, but my thinking is the necessary features are there to make this happen, which are: url hooks https://processwire.com/blog/posts/pw-3.0.173/ $input->requestMethod https://processwire.com/api/ref/wire-input/request-method/ $config->sessionAllow (I should disable sessions probably to example.com/api/*) https://github.com/processwire/processwire/blob/master/wire/config.php#L375 one of these authentication methods https://blog.restcase.com/4-most-used-rest-api-authentication-methods/ Any thoughts on this or recommendations? Link to comment Share on other sites More sharing options...
elabx Posted October 4, 2023 Share Posted October 4, 2023 About URL hooks Not sure it has change but once happened to me that I couldn't do optional segments, example: /get-images/{page}/{field}/ Request wouldn't reach if I tried to get to: /get-images/{page}/ Then I think the concept of middleware is not present? So say you want to block unauthenticated calls, check CSRF, etc, you'd have to make that check on every route hook. Probably AppApi is still the way to go, feature wise? Project seems very alive! Edit: Just reading AppApi actually uses path hooks to bootstrap its endpoints. 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 4, 2023 Share Posted October 4, 2023 6 hours ago, Jonathan Lahijani said: I haven't seen discussion on this There has been a lot of discussion here ? https://processwire.com/talk/topic/26792-headless-processwire-how-do-you-do-it/ 4 hours ago, elabx said: Not sure it has change but once happened to me that I couldn't do optional segments, example: /get-images/{page}/{field}/ I think this should work: /get-images(/{page})?(/{field})?/ ? 2 Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted October 5, 2023 Author Share Posted October 5, 2023 3 hours ago, bernhard said: There has been a lot of discussion here ? https://processwire.com/talk/topic/26792-headless-processwire-how-do-you-do-it/ I saw that thread before I wrote this post, but I seemed to have missed the few references to using URL hooks. Thinking this further, I should consider using AppApi first before trying to roll my own solution. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now