Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marydn/star-wars
Guzzle Middleware to send third-party API responses to Redis cache
https://github.com/marydn/star-wars
api api-client api-rest guzzle guzzle-middleware guzzlehttp middleware php php7 redis
Last synced: about 1 month ago
JSON representation
Guzzle Middleware to send third-party API responses to Redis cache
- Host: GitHub
- URL: https://github.com/marydn/star-wars
- Owner: marydn
- Created: 2020-02-02T19:54:01.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T14:23:38.000Z (about 2 years ago)
- Last Synced: 2024-11-07T05:14:30.047Z (3 months ago)
- Topics: api, api-client, api-rest, guzzle, guzzle-middleware, guzzlehttp, middleware, php, php7, redis
- Language: PHP
- Size: 803 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## 🚀 Environment setup using Docker
### 🐳 Needed tools
1. [Install Docker](https://www.docker.com/get-started)
2. [Install npm](https://www.npmjs.com/get-npm)
3. [Install yarn](https://classic.yarnpkg.com/en/docs/install)
4. Clone this project: `$ git clone https://github.com/marydn/star-wars`
5. Move to the project folder: `$ cd star-wars`
6. Generate assets: `$ yarn install && yarn build`### 🛠️ Environment configuration
1. By default, Redis TTL is set to 300 seconds.
To override this parameter:
```bash
$ touch .env.local
$ echo 'REDIS_TTL=XXX' >> .env.local # where XXX is the desired int value
```### 🌍 Application execution
1. Start the project: `$ make build`
This will install PHP dependencies and bring up the project Docker containers with Docker Compose.2. Check everything's up: `$ docker-composer ps`
It should show nginx and php services up.
3. Go to `http:://localhost:8000` in your browser
### Some Docker commands
- Bringing up the project using Docker: `$ make`
- Bringing down the project: `$ make destroy`
- Rebuild Docker images forcing latest versions and ignoring cache: `$ make rebuild`### ✅ Tests execution
1. Install PHP dependencies if you haven't done so: `$ make deps`
2. Execute PHP Unit tests: `$ make test`## 🤔 Project explanation
It's a simple form that let you query an endpoint and print the result into a table using XMLHttRequest.
Every request made is cached in Redis using a Middleware (`src/Service/Middleware/CachedMiddleware.php`)```bash
$ tree -L 4 src
src
├── Controller
│ ├── HomeController.php
│ └── JsonController.php
├── Public
│ ├── js
│ │ └── entry.js # This is for webpack
│ └── vue
│ └── ApiFetcher.vue # Javascript component for front
└── Service
├── ApiConsumer.php # Service to wrap third-party requests
├── Middleware
│ └── CachedMiddleware.php # Middleware that allows to call a cache wrapper per API call
├── Normalizer
│ └── GuzzleResponseNormalizer.php # Normalize Guzzle Response Objects to save and retrieve to/from Redis
└── RedisCache.php # Some methods to handle Redis transactions
```