Giter Club home page Giter Club logo

Comments (5)

prezire avatar prezire commented on May 20, 2024

Are you referring to a simplified version of Laravel's Resource Controllers? https://laravel.com/docs/5.3/controllers#resource-controllers

from codeigniter4.

lonnieezell avatar lonnieezell commented on May 20, 2024

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.

prezire avatar prezire commented on May 20, 2024

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.

lonnieezell avatar lonnieezell commented on May 20, 2024

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.

prezire avatar prezire commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.