mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database
MIT License
3.61k stars 1.01k forks source link

Fully functional bootstrapped application #713

Open vascanera opened 4 years ago

vascanera commented 4 years ago

Hello Maurits, This is more of a request than it is an actual issue, but I think the value in this request is really high (for newcomers, especially - but not limited to). Could you please add a COMPLETE application example of using the API (with user authentication, maybe even with the user-creation SQL script, table authorization, etc). This would be really really helpful as a quickstart / bootstrap for new applications. Maybe create it as a separate project (in its own repo) that we can further extend to cover more and more of the existing functionality and middlewares. Or, is there anything like that already available? (and I am not aware of). Thanks a lot! Keep up the good work!

mevdschee commented 4 years ago

First of all: thank you for your kind words!

Could you please add a COMPLETE application example

I agree that "the value in this request is really high" and I did do some efforts in that direction.

On the other hand I cannot anticipate how people use this technology as it really is a building block with many ways to use or incorporate it and it is not an application in itself. Also many people want to "keep it simple", so "complete" may mean different things to different people.

Below you find some of my efforts. Maybe the community has some more examples.

mevdschee commented 4 years ago

Did you see php-crud-ui? It may not be the architecture you had in mind, but I can assure you that it is fast and easy to debug/extend. It is a lot of work to create a good (and complete) application on top of this, but I did try :-). Suggestions, additions and/or improvements are very welcome!

Did you see vue-crud-ui? It may not be complete at all, but it was fun to build and should be easy to extend. I'm not much of a front-end guy, so I haven't updated this project in a while. It may be close to what you have in mind, or isn't it?

mevdschee commented 4 years ago

I agree that adding security is difficult, but there are many ways to deal with authentication and authorization:

Same goes for authentication:

There are so many options for each of these problems and I intend to support them all. That's why I made the project loadable as a library in Laravel, Symfony and SlimPHP. But please tell me, what would you consider "complete"?

vascanera commented 4 years ago

I would consider username/password authentication as "complete" - at least from a newcomer's perspective. Maybe later, JWT or something like that. The idea is to copy/clone the bootstrap application and to be able to create an API using as little php code as possible. Only the bare minimum configuration code should do the trick. Nothing too fancy.

mevdschee commented 4 years ago

The idea is to copy/clone the bootstrap application and to be able to create an API using as little php code as possible.

What if you use a Laravel example application and add this lib for the REST API? Would that fit your goal?

In the following blog post I've explained how to add the API to an existing Laravel (demo) application:

https://tqdev.com/2019-automatic-rest-api-laravel

NB: If you want to build such a demo application, then I'm happy to contribute to it and to promote it (as good as I can)!

vascanera commented 4 years ago

Hello. Regarding the Laravel example, I think it defeats the purpose of simplicity. A Laravel basic application using php-crud-api, compared to a php-only "setup-the-config-and-go" application looks like a convoluted mess - and by this, I mean there are just too many steps to accomplish in setting it up (I know, for a Laravel accustomed dev it looks really simple and short!). I appreciate Laravel and other "big boy" frameworks for what they are and for the problems they solve, but there's just too much boilerplate code for the same return (of investment). Let's say I don't want to learn any (new) php framework, I just need the API to work, to expose a DB and have some user/pass authentication, and that's all. The rest should be just fine-tuning that config object for api.php for some custom table/column/path rules. I might start building such an example application myself, but my time is a bit tight right now. I hope I have explained my request a little better this time. Keep it up!

scriptPilot commented 1 year ago

If anyone is interested, for Vue I have created some handy bindings to deal with this API :-)

https://github.com/scriptPilot/vueuse/

mevdschee commented 1 year ago

If anyone is interested, for Vue I have created some handy bindings to deal with this API :-)

Thank you! I added that to the README for everyone to enjoy.

see: https://github.com/mevdschee/php-crud-api/commit/d030eb2b800992e81336a9b2c9e6dd1122ca1b1b