Welcome Guest, Not a member yet? Register   Sign In
CI as a backend API framework
#1

(This post was last modified: 12-26-2022, 11:54 PM by ruslan.)

I wonder if it makes sense to have a version/flavour of CI for API based backends (RESTful, JSON-RPC, just json etc)
The web dev world is moving to SPA for the last decade and CI is very good as a framework for backend API
There are not used parts for that like View, Session
May be ResouceControler can be improved
Simple JWT auth plugin/filter (the Shield is way overcomplication)
Also, `debugbar` should be in json format, not html/javascript to be readable in Postman for example. That's a must in any case.
Just thoughts
Reply
#2

You are right @ruslan even me this is what I have been %100 rethinkings anyway
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

You have a lot of great points and I completely agree, CI4 is a wonderful and practical framework to use as a JSON based backend for any web application, such as an SPA, PWA or a REST API.

First, CI4's APIResponseTrait makes it super easy to build controllers that do whatever business logic you require and easily return the answer as JSON. Also, the IncomingRequest class makes it easy to either catch URL parameters (such as a GET) or JSON and break it up to use in your logic.

I use CI4 almost exclusively as a back end framework and I have just forged my own needs into it as I go. I don't really use the ResourceController functionality myself, I just build what I need. Sometimes I need to return HTML so the View and ViewCells functionality is a great optional add on that can be disregarded if it's not needed.

This is a perfect JWT library for any PHP framework (even CI4) that I use all the time. You need to decide for yourself what information you want to store in your JWTs but encoding/decoding them is a breeze using the simple methods contained in this library: https://github.com/firebase/php-jwt

Finally, while I agree that the debug bar is not really useful when building REST APIs (that don't involve the browser), for testing purposes my recommendation is to use the built in Kint library for debugging. By simply using the dd() method and placing whatever information you want in the parentheses, Kint will feed you every bit of important information back and you'll know exactly what you're working with.

In short, with a few personalizations and modifications, CI4 already makes a wonderful framework to build a backend API for many different types of front ends to feed from.
Reply
#4

I agree with you @viewfromthenorth that exactly as a backend API framework CI outperforms other PHP alternatives the most - both in result and in DX (developer experience). And i think that improvement of CI in this direction can attract significantly more users to it.

I use firebase/php-jwt package too, it's a standard de-facto, but i would like to have in CI (as a plugin may be) a well-designed component for JWT authentication with refresh token logic.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB