Comments (5)
Are you referring to a simplified version of Laravel's Resource Controllers? https://laravel.com/docs/5.3/controllers#resource-controllers
from codeigniter4.
Nope. CI already has Resourceful Routes. In this, I'm talking about common response methods for a number of the most frequently used responses in API's. This would set the correct HTTP status code, default message, etc and send the response, thus helping a user keep a consistent, and accurate response when doing RESTful API's.
I've got one of these partially finished that I've used in a few other projects that I need to revisit, expand, and re-research to ensure they're still meeting best practices.
from codeigniter4.
You mean something like this?
// Structure.
{
success: bool,
status_code: int,
data: array,
message: string
}
// Sample success.
{
success: true,
status_code: 200,
data: [{id: 1, full_name: 'a'}, {id: 2, full_name: 'b'}],
message: 'Students list.'
}
// Sample failed.
{
success: false,
status_code: 404,
data: [],
message: 'Record not found.'
}
// Some method.
public function Api::response(int $statusCode, array $data, string $message);
from codeigniter4.
No, what I had used previously were a series of methods that made it easier to remember, like failValidation()
, failUnauthorized()
, etc. That way you didn't have to remember which status codes were for each state.
There's enough discussion about certain status' that it would be wise to make those customizable.
Another wrinkle is that we need to determine exactly how we're going to handle response formatting, if we do it at all. And there has been discussion internally about the possibility of formatting responses as XML, JSON, JSONP, etc, from model results, but no firm decision made just yet.
from codeigniter4.
I see. Wouldn't it be best to use constants or static variables for the codes? But in any case, I'm excited for the final decision.
from codeigniter4.
Related Issues (20)
- Bug: CI4 + Shield + Postgre Spark error HOT 3
- Bug: bootstrap on `preload` not updated to last v4.5.1 HOT 1
- Bug: [ErrorException] Undefined array key "opcache.enable" HOT 1
- Bug: [Model] when the query ($this->first()) result returns NULL we get TypeError HOT 2
- Bug: [OCI8] Argument #1 ($value) must be of type ?int, string given HOT 2
- Bug: Invalid date format for ORACLE database for created_at and updated_at HOT 2
- Bug: Entity::$dataCaster must not be accessed before initialization HOT 1
- How to add CI4 in a raw project and use the database class? HOT 2
- Bug: calling force_https() in 404 controller causes error HOT 8
- The lang function exposes the name of your language file if there is no record. HOT 1
- Bug: Error when run php spark cmd in testing env HOT 2
- Bug(SQLite3): Forge::dropColumn() seems to always return false HOT 1
- Bug: [DatetimeCast] Invalid parameter: nullable HOT 3
- Bug: CLI class, method promptByMultipleKeys() - default $input is of wrong type HOT 1
- Bug: No DBPrefix or backticks inside SQL functions in QueryBuilder HOT 16
- Bug: Can not header reponse as file image HOT 2
- Bug: [View Cells] Too few arguments to function App\Cells\MyClass::myMethod(), 0 passed in HOT 3
- Bug: CodeIgniter\Controller::validateData will throw error if first paramter is not an empty array for file upload validation HOT 4
- Bug: language fallback doesn't kick in if message if empty HOT 5
- Bug: Session FileDriver unlink No such file or directory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter4.