Download the PHP package galafeno/lingo without Composer
On this page you can find all versions of the php package galafeno/lingo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package lingo
Lingo
Lingo is a package for Laravel that provides a layer of abstraction to any REST service. so it is possible to encapsulate http communication concepts in a much closer object-oriented design and thus improve developer experience.
Installation
Use the package manager composer to install Lingo.
Usage
Use the command make:lingo
to initialize a new Lingo inside your application.
That command creates a class called AwesomeApiLingo
within the folder App\Lingos
.
To model the API you should add the endpoints inside the sync
section into the AwesomeApiLingo
class.
After that, you can use your Lingo inside your application like so:
The command
method should receive at least one parameter (the command name). In that case it received 2 parameters because the getMovie
command has a binding value (marked with the {:?}
wildcard).
Custom Headers
Lingo was designed to handle json data type, so it will always append the Content-Type: application/json
and Accept: application/json
into default headers. To define another headers, create a headers
property into your Lingo Class
That will produce the follow headers in every request:
You can also define extra headers in runtime like so:
Query parameters
To define query parameters, create a params
property into your Lingo Class
That will insert the follow query parameters in every request:
You can also define extra query parameters in runtime like so:
Body Parameters
To define body parameters, create a data
property into your Lingo Class
That will insert the follow body parameters in every request:
You can also define extra body parameters in runtime like so:
Closure Commands
Usually you should use Lingo as a way to map endpoints into commands. But using closure command syntax you can trigger a function instead of a real http request. That is a convenient way to append metadata about your api. To do so, use the keyword function inside your command configuration. Then just add the referred function in your Lingo class.
Handling Authentication
In real world applications REST services implements some type of authentication scheme. If you are dealing with a simple approach like a signature or key into request headers you should simply use the withHeaders
command to attach your auth configuration into Lingo. But some services utilizes specifics schemes. To handle it you should define an auth
configuration within your lingo class. currently, this package supports apiKeys
and oauth2
auth methods.
apiKeys
That method will attach the key configuration as a query parameter.
oauth2
That method will handle the oauth2 flow to retrieve the jwt and cache it using your application cache configuration.
Mockup mode
While testing your application you must define APP_ENV=testing
in your .env
to activate Lingo mockup mode. While using this mode the package will bypass any real request by a mocked static data. You should define that data within your command configuration section using the shouldReturn
key.
You can also set mockup mode in runtime like so:
Lingo use static
as default mockup data mode. But you may set function
mode with the mockup
keyword. with that, Lingo will rely on a function to generate the mockup data.
Async Communication
If your application utilize AWS infrastructure you may configure asynchronous message within your Lingo class. To do so, you must configure your async
section.
To send a asynchronous you have to use the async
method.
That will push to your sqs queue the payload:
Roadmap
- [ ] unit and feature tests
- [ ] export
sync
section to a swagger file - [x] accepts a closure into
shouldReturn
section, so you can deal with dynamically generated mockup data - [ ] add a polymorphic option into
make:lingo
. it will be nice create, for instance aPaymentLingo
that is a interface and aStripeLingo
as a concrete class that implementsPaymentLingo
- [x] to allow a sync command trigger a closure or a class method instead of a http request.
- [ ] custom exceptions
- [ ] a built-in log system
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.