Skip to content

Laravel Composer Package for Automated API Response Generation, Including Pre-configured Methods for Status Code Handling.

License

Notifications You must be signed in to change notification settings

navjotsinghprince/http-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Response Package Introduction

License

Laravel Composer Package for Automated API Response Generation, Including Pre-configured Methods for Status Code Handling.

Installation

composer require princeferozepuria/http-response

Import HTTPResponse

use Prince\Ferozepuria\HTTPResponse;

Extending and Usage

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Prince\Ferozepuria\HTTPResponse;
use Illuminate\Support\Facades\Validator;

//Feel Free To Visit https://navjotsinghprince.com
class TestController extends HTTPResponse {
    

    /**
     * Example 1...
     */
    public function example1(Request $request)
    {
        $collection = collect([1, 2, 3]);

        $class_Obj = new \stdClass();
        $class_Obj->name="Prince Ferozepuria";

        $response = [
            "string" => "Prince Ferozepuria",
            "int" => 1,
            "boolean" => true,
            "array" => ["prince", "ferozepuria"],
            "collection" => $collection,
            "class_object" => $class_Obj,
            "is_null" => null,
            "is_empty" => "",
        ];

        return $this->sendSuccess(SUCCESS,$response);

      }


    /**
     * Example 2...
     */
    public function example2(Request $request)
    { 
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email'=>'required|email'
        ]);

        if ($validator->fails()) {
            return $this->validationFailed(ALL_FIELDS_REQUIRED, $validator->errors());
        }

      }


    /**
     * Example 3...
     * Usage With Custom Object
     */
    public function example3(Request $request)
    { 
        $data = ["name" => "Prince Ferozepuria"];

        $response = new HTTPResponse();
        return $response->sendSuccess("This is just test message", $data);

    }

      
    }

Available Methods

<?php

   $response = [
      "name" => "Prince Ferozepuria",
      "email" => "fzr@navjotsinghprince.com",
      "website" => "https://navjotsinghprince.com"
    ];

    return $this->sendSuccess("success response message", $response);

    return $this->sendSuccessForce("success force response message","total",$response);

    return $this->sendFailure("failed response message",$response);

    return $this->notFound("not Found response message",$response);

    return $this->validationFailed("validation failed response message",$response);
    
    return $this->forbidden("forbidden response message");

    return $this->unauthorized("unauthorized response message");

    return $this->dataProcessFailed("data process failed message");

Tips

💡 Tip: Use Available Messages: SUCCESS , FAILED , ALL_FIELDS_REQUIRED , SOMETHING_WRONG , SOMETHING_WRONG_LATER

Authors

👉 Navjot Singh Prince

See also the site of contributor who participated in this package.

Contact

If you discover any question within package, please send an e-mail to Prince Ferozepuria via fzr@navjotsinghprince.com. Your all questions will be answered.

Changelog

Please see changelog.md for what has changed recently.

Buy Me A Coffee! ☕

Feel free to buy me a coffee at Buy me a coffee! ☕, I would be really grateful for anything, be it coffee or just a kind comment towards my work, that helps me a lot.

Donation

The package is completely free to use, however, it has taken a lot of time to build. If you would like to show your appreciation by leaving a small donation, you can do so by clicking here here. Thanks!

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Laravel Composer Package for Automated API Response Generation, Including Pre-configured Methods for Status Code Handling.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages