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: [DebugBar] Flush a session flash-data when redirect by "Refresh" method HOT 2
- Add required_if validation rules
- Bug: Entity Standalone Class initialization error HOT 2
- Bug: How can I know which browser name is the request from?
- Bug: How can I know which browser name is the request from? HOT 14
- Bug: storing validation rules in Config/Validation causes error HOT 1
- Bug: Fatal error: Uncaught Error: Undefined constant "ENVIRONMENT" in /var/www/html/MyApp/system/Common.php:777 HOT 1
- Bug: cannot run PHPUnit testing in CI 4.5.1 appstarter HOT 5
- "Deploy API Documentation" fails HOT 1
- Composer PSR-4 notices "does not comply with psr-4 autoloading standard" HOT 16
- Bug: CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in system\Router\DefinedRouteCollector.php on line 49 HOT 3
- Bug: `migrate:rollback -b` impossible due to TypeError HOT 4
- Bug: [Validation] if_exist is not working as intended with arrays HOT 1
- Bug: spark routes doesn't work with `(.+)` HOT 2
- Bug: nested $routes->group() with same filter name doesn't work as exepcted HOT 14
- Bug: system/Database/OCI8/Connection.php fails to parse valid DSN HOT 10
- Bug: When Install fresh codeigniter 4 Project I am getting "does not comply with psr-4 autoloading standard" HOT 1
- Bug(OCI8): $validDSNs regex for Oracle service names should support periods HOT 1
- Bug: [QueryBuilder] select() TypeError: trim(): Argument #1 ($string) must be of type string, CodeIgniter\Database\RawSql given HOT 4
- Validation `valid_date` does not work with time HOT 2
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.