This is a mock API that simulates a real API.
When receiving an unknown request, it will return a 501 status code and save the URL in the database.
Now you can add the response to the database and the next time the same request is made, the API will return the response you added.
This project is created with Laravel. I recommend to run it with Laravel Herd and a SQLite database.
If you want to reach the API from a Docker container, you need to find the IP of your host and add this to your domain. Let's say your MOCK API URL is mock-api.test
. Go into your docker container and check the IP of your host:
$ ping host.docker.internal
64 bytes from 192.168.1.1 icmp_seq=1 ttl=63 time=0.267 ms
Add this IP to your domain in the /etc/hosts
file:
$ echo "192.168.1.1 mock-api.test" >> /etc/hosts
Now you can reach the API from your docker container with mock-api.test
.