vendredi 28 septembre 2018

PHP REST API with nested routes

I want to create a pure PHP REST API and I am quite new in backend development field, but I am experienced software developer, so some concepts are known to me.

However, after watching several tutorials on how to create REST API with PHP, all instructors were using simpler examples, where no nesting exists.

Simple Example:

GET /api/category/read.php

However, I want to create something like this:

GET /api/{user_id}/{folder_id}/{file_name}/read.php

I am struggling to find any tutorial covering this with PHP. And I have spent several hours trying to figure it out by myself by trying to modify the code I have seen in Tutorial videos. I mean if I do like they do, this would mean manually creating folders in my Project Folder for each {user_id} and so forth for each sub-folder... but I do not think that such hardcoding is the solution.

I have found some SO questions here relating closely to my question, but none have satisfying answers - makes me wonder that this if this is possible to do at all. But it seems so common (for example, I know that GitHub API has just that support /{user}/repos) so I think it should be doable.

I would be really grateful if someone could help me out how to accomplish my goal. If not else, pointing to a tutorial / documentation that does just that is equivalently appreciated!




Aucun commentaire:

Enregistrer un commentaire