Download the PHP package laragear/api-manager without Composer

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

Api Manager

Latest Version on Packagist Latest stable test run Codecov coverage Maintainability Sonarcloud Status Laravel Octane Compatibility

Manage multiple REST servers to make requests in few lines and fluently. No more verbose HTTP Requests!

Become a sponsor

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!

Requirements

Installation

Require this using Composer into your project:

Usage

Creating an API Server

To make use of an API server, define a class that extends Laragear\ApiManager\ApiServer. You may use the make:api Artisan command to make a ready-made stub in the app\Http\Apis directory.

You will receive a file with a base URL and actions, and space to add some headers and a bearer token. You're free to adjust it to your needs.

[!NOTE]

You can override the API Server stub creating one in stubs/api.stub.

Inline Actions

Setting actions in the API class solves the problem of having multiple endpoints and preparing each one every time across your application, which can led to errors or convoluted functions full of text.

The easiest way to define actions is to use the $actions array using the syntax verb:route/{parameters}, being the key the action name you will invoke later. If you don't define a verb, get will be inferred.

For example, to update a chirp, we could call edit directly from our ChirpApi.

While you're at it, add the PHPDoc manually to your API Server to take advantage of autocompletion (intellisense).

Then, call the action name in camelCase notation. Arguments will be passed down to the HTTP Request.

If the route has named parameters, you can set them as arguments when invoking the server.

Also, you can call an action without arguments as it were a property.

Method actions

For more complex scenarios, you may use a class methods. Just be sure to type-hint the PendingRequest on any parameter if you need to customize the request.

Then later, you can invoke the class methods like any monday morning.

[!NOTE]

Method actions take precedence over inline actions.

As with inline actions, method actions can be also executed as it where properties if these don't require arguments.

Authentication

An API Server supports the three types of authentication of the HTTP Client in Laravel: Basic, Digest and Bearer Token. You may define each of them as an array of username and password using authBasic() or authDigest(), and authToken() with the token, respectively.

[!WARNING]

Don't use an associative array to match the underlying methods. Since Laravel doesn't warranty consistency on named arguments, you should opt for simple arrays.

Before & After building a requests

You have the option to modify the request before and after it's bootstrapped using the beforeBuild() and afterBuild() respectively. The beforeBuild() is executed after the PendingRequest instance receives the base URL, and the afterBuild() is called after the headers and authentication are incorporated.

You're free here to tap into the request instance and modify it for all endpoints, or return an entirely new PendingRequest instance.

[!TIP]

If you're using the old build() method from previous versions, it will still work since the beforeBuild() will call to build().

Overriding a request

The API request can be overridden as usual. All methods are passed down to the Illuminate\Http\Client\PendingRequest instance if these don't exist on the API Class.

[!NOTE]

If the method exists in your API Class, it will take precedence.

Dependency Injection

All API Servers are resolved using the Service Container, so you can add any service you need to inject in your object through the constructor.

You can also create a callback to resolve your API Server in your AppServiceProvider if you need more deep customization to create it.

Concurrent Requests

To add an API Server Request to a pool, use the onPool() method for each concurrent request. There is no need to make all requests to the same API server, as you can mix and match different destinations.

You may also name the requests using a second argument to on().

Wrapping into custom responses

You may find yourself receiving a response and having to map the data to your own class manually. Instead of juggling your way to do that, you can automatically wrap the incoming response into a custom "API Response".

First, create a custom response for an api using make:api-response, the API you want to use, and name the custom response with the same name of the endpoint. Ideally, you would want to name it the same as the action or method you plan to use it for.

You will receive a file like this:

[!NOTE]

You can override the API Response stub creating one in stubs/api-response.stub.

In this class you can make any method you want. Since your class will extend the base Laravel HTTP Client Response class, you will have access to all its convenient methods.

Once you finish up customizing your custom API Response, you may map it to the actions and methods using the $responses array of your Api class.

This will enable the API Manager to wrap the response into your own every time you call that method to receive a response. For example, if you call view(), you will receive a new ViewResponse instance.

[!TIP]

When using async() requests, custom responses are automatically wrapped once resolved.

Testing

You can easily test if an API Server action works or not by using the fake() method of the HTTP facade.

Laravel Octane Compatibility

There should be no problems using this package with Laravel Octane.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

This specific package version is licensed under the terms of the MIT License, at time of publishing.

Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2024 Laravel LLC.


All versions of api-manager with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/guzzle Version ^7.5
illuminate/http Version 10.*|11.*
illuminate/config Version 10.*|11.*
illuminate/container Version 10.*|11.*
illuminate/support Version 10.*|11.*
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 laragear/api-manager contains the following files

Loading the files please wait ....