How can I expose api-end points for the CRUD controllers used for backpack so that I can reuse the operations in the controllers without having to code new ones, while adding necessary api features like JSON, authentication modes
Asked
Active
Viewed 563 times
2
-
1The endpoints themselves are exposed. The routes get created like routes normally do, you could hit these routes with an ajax request and should be able to interact with them just fine. That said, you may have at least 2 obstacles. 1) CSRF Token middleware for those routes, you'll need to supply a valid token from the page, or disable the middleware. 2) The response you get will likely be html in at least some cases. – Wesley Smith Nov 09 '19 at 04:41
-
Are you using Backpack v3.X or v4? – Wesley Smith Nov 09 '19 at 04:43
-
I am using Backpack v4 – Stephen Senkomago Musoke Nov 09 '19 at 08:07
1 Answers
3
Looks like Backpack routes work like API end-points for XHR requests, so adding a header HTTP_X-Requested-With
with a value XMLHttpRequest
causes backpack to return with JSON

Stephen Senkomago Musoke
- 3,528
- 2
- 29
- 27