Download the PHP package juampi92/api-resources without Composer

On this page you can find all versions of the php package juampi92/api-resources. 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 api-resources

Api Resources

Latest Version GitHub Tests Action Status Total Downloads

Manage your resources maintaining API versioning. With a simple middleware separate routes by api version, and smart instanciate Http\Resources based on this version.

Add the middleware 'api.v:2' on your api/v2 group.

And then api_resource('App\User')->make($user) is the same as new App\Http\Resources\App\v2\User($user), but version free.

The idea behing this

A while back I faced this API versioning problem, so I wrote this medium post with my solution and this package reflects this.

Installation

You can install this package via composer using:

The package will automatically register itself.

Config

To publish the config file to config/api.php run:

This will publish a file api.php in your config directory with the following content:

Middleware

Install this middleware on your Http/Kernel.php under the $routeMiddleware

Configure correctly

For this package to work, you need to understand how it requires resources.

If we have the following config:

This means that if you include the Api\User resource, it will instantiate App\Http\Resources\Api\v2\User.

Api works for sub organizing your structure, but you can put your Resources versionate folders in the root, like this:

Now if we include User, it will instantiate App\Http\Resources\v2\User.

Fallback

When you use a version that is NOT the latest, if you try to include a Resource that's NOT defined inside that version's directory, this will automatically fallback in the LATEST version.

This way you don't have to duplicate new resources on previous versions.

Usage

Middleware

When you group your API routes, you should now apply the middleware api.v into the group like this:

That way, if you use the Facade, you can check the current version by doing APIResource::getVersion() and will return the version specified on the middleware.

Facade

There are many ways to create resources. You can use the Facade accessor:

Global helper

Collections

Instead of make, use collection for arrays, just like Laravel's documentation.

If you wanna use a ResourceCollection, you might wanna rewrite the collects() method.

This way, the ResourceCollection will always have the correct class.

resolveClassname will try to use the current version of the class, but if it's not possible, will use the latest.

Nested resources

To take advantage of the fallback functionality, it's recomended to use api_resource inside the resources. This way you preserve the right version, or the latest if it's not defined.

Multiple APIs

There might be the case where you have more than one API living on the same project, but using diferent versions. This app supports that. First, the config/api.php

Then, you need to configure the middleware. Instead of using api.v:1, you now have to specify the name: api.v:3,desktop.

Then the rest works as explained before.

API Route

Sometimes you must return a route url on the api response. If you wanna keep the api version (which is always the current version), api-resources has the solution for you.

With this we have api.v1.auth.login and api.v2.auth.login when creating a new version.

Now just do api_route('api.auth.login'), and it will output /api/v1/auth/login or /api/v2/auth/login accordingly.

How it works

It's grabbing the config api.resources and doing a strtolower, so if you have 'resources' => 'App', will transform app.auth.login into app.v1.auth.login. If you need to customize it, add a new config entry in config/api.php like this:

If works with multiple APIs as explained before.

Testing

Run the tests with:

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of api-resources with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0|^8.1|^8.2
illuminate/support Version ^7.0|^8.0|^9.0|^10.0
illuminate/http Version ^7.0|^8.0|^9.0|^10.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 juampi92/api-resources contains the following files

Loading the files please wait ....