Library

Storage API Service

Visit Github repository

Storage API Service

This library is a microservice that stores files using league/flysystem filesystem abstraction.

It was built to allow our development teams at 2am.tech to avoid having to configure storage adapters over and over on projects involving a microservices infrastructure. It's a combination of two separate applications, one being Symfony's CI application and the other being an API built with Slim3.

The project uses Monolog for logging, Fractal as a serializer, Tactician as a command bus, Basic access authentication and Json Web Tokens for authentication (this is optional), Zend filter for data filtering and validation, and Phinx for database migrations.

Docker compose and Postman collection files are included for easy development, even though docker is not strictly necessary for development as you could easily use the built-in PHP server.

Install

Install the latest version using composer.

$ composer create-project --no-interaction --stability=dev 2amigos/storage-service app

Configuration

The project uses environment files to configure secrets. For that reason, you must create a file named .env in the root directory of the project. An .env.example file has been provided with all required environment values. Modify that file and save it as .env in the root directory.

By default, the API application is configured to work under basic authentication processes. It uses an array of users for that purpose but you could easily change that behavior by configuring the authenticator option of the HttpBasicAuthentication middleware by creating your own or using one provided by the library. Check the PdoAuthenticator.

If authentication is successful, the action will return a Json Web Token to be used for subsequent calls.

Authentication, or the usage of scopes, are optional. If you don't wish to work with this kind of setup, simply remove the middleware configurations of HttpBasicAuthentication, JwtAuthentication and ScopeMiddleware middlewares.

Usage

Create a database with the credentials that you used in .env file. Now you can run Phinx database migrations with this command:

./vendor/bin/phinx migrate -e development

For the sake of this example, go to the public folder of the app and start the built-in PHP server like this:

php -S localhost:8080

Now we can access the api at http://127.0.0.1:8080.

Get a token

To get a token, do the following:

1$ curl "https://127.0.0.1:8080/token" \
2--request POST \ 
3--include \ 
4--insecure \ 
5--header "Content-Type: application/json" \ 
6--data '["mail.all"]' \ 
7 --user test:test
8
9# response
10HTTP/1.1 201 Created
11Content-Type: application/json
12{ 
13"data": { "token": "XXXXXXXXXX", "expires": 1550271641 }
14}

For further information, please refer to its documentation at github.

Tags: Technology, Design, Computer
Share with

Contributors

Thanks All

tonydspaniard
Terms of Use | Privacy Policy