Download the PHP package fenox/laravel-api-json without Composer

On this page you can find all versions of the php package fenox/laravel-api-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api-json

JSON API Base Package for Laravel

Table of Contents

Description

The API Base Package for Laravel is designed to streamline API development by automating the creation of essential components. It facilitates the rapid generation of models, migrations, controllers, requests, policies, seeders, factories, and tests, significantly reducing the amount of boilerplate code developers need to write.

This package ensures that all API responses are consistently returned in JSON format, providing a uniform approach to error handling and data interaction across your application. With built-in validation and error handling, the package improves developer efficiency while maintaining best practices in API development.

Key features include:

The package is perfect for developers looking to set up a robust API quickly and efficiently while maintaining flexibility for future enhancements.


Requirements

To use the API Base Package for Laravel, ensure that your development environment meets the following requirements:

Recommended Environment


Installation

To get started with the API Base Package for Laravel, follow these steps:

  1. Create a new Laravel project (if you haven't already):

  2. Navigate to your project directory:

  3. Install the API Base Package: Use Composer to require the package:

  4. Publish the authentication resources: After installing the package, publish the authentication-related resources:

    This will create necessary request classes and controllers to handle authentication, which you can customize as needed.

  5. Run the API routes installation command (if applicable): To set up your API routes, run:

Usage

The API Base Package simplifies the process of creating and managing API endpoints. To create a new API model along with its associated components, use the make:apimodel command.

Example: Creating a Category API

  1. Run the command: To generate the Category API, execute the following command:

  2. Modify the Migration File: After generating the model and migration, navigate to the migration file in to add the necessary fields for your database schema. For instance, if you're adding and fields, your migration might look like this:

  3. Add `` Fields to the Model: In your model file located at , ensure you add the necessary fields to the property to allow mass assignment:

  4. Define Validation Rules in Requests: In the generated and files located in , set your validation rules. If a field is optional, use or :

  5. Setup Routes: Ensure your API routes are configured properly in . The generated routes will typically look like this:

    By following these steps, you can quickly set up a functional CRUD API for the Category model, ready for further customization and use.

    Remember use:

    & run:


Auth

his package integrates Laravel Sanctum to provide simple and robust API token authentication for your application.

Steps to Setup Authentication

  1. Publish the Auth Requests: After installing the package, you can publish the authentication-related requests by running:

  2. Modify the User Model: Ensure that your model (located at ) uses the trait. This allows the model to generate API tokens for authentication:

  3. Setup Routes:The package will generate the necessary authentication routes automatically. You should add the following routes to your file to enable login and logout functionality:

Error Handling

This package includes built-in error handling to ensure that all exceptions and validation errors are consistently returned in JSON format. This approach improves the uniformity of API responses and simplifies client-side error management.

Common Error Responses

The following are the common error responses that the package handles:

  1. Validation Error (422): When a request fails validation, a structured error response is returned. For example:

  2. Unauthenticated (401): Returned when a user attempts to access a protected resource without proper authentication.

  3. Forbidden (403): Returned when an authenticated user does not have permission to perform a specific action.

  4. Resource Not Found (404): Returned when a requested resource or route is not found.

  5. Method Not Allowed (405): Returned when the HTTP method used for a request is not allowed for the specified route.

  6. Server Error (500): Returned for any unexpected server errors.

Advanced Configuration

This package provides a base structure for API development, but it can also be customized or extended depending on your project’s needs.

  1. Customizing Controllers

    By default, the generated controllers extend the provided by this package. You can customize these controllers by overriding methods like , , , and more to add additional logic or behavior.

    Example: Modifying the

  2. Adding New Functionality

    You are free to extend this package by adding new commands, controllers, or services specific to your API structure.

    Example: Adding a Custom Base Controller

    You can extend the to create new functionalities shared across your API controllers. For example, you could add new methods or modify existing ones.


Contributing

We would be delighted to receive contributions to improve this package and its functionality. If you find any bugs or have suggestions for new features, please report them by opening an issue on our GitHub repository. Your feedback and contributions are invaluable to us!


License

This package is open-sourced software licensed under the MIT license.

You are free to use, modify, and distribute this package under the terms of the MIT license. For more details, refer to the LICENSE file included in this repository.



All versions of laravel-api-json with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fenox/laravel-api-json contains the following files

Loading the files please wait ....