- Clone repository
- Run
docker-compose up -d - Copy .env.example, rename to .env and configure
- Run
docker-compose exec php php artisan migrate - Run
docker-compose exec php php artisan testto running tests - Go to terminal and send curl request
curl --location 'http://127.0.0.1:8000/api/submit' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "John Doe",
"email": "john.doe@example.com",
"message": "test message"
}'- API Endpoint: Develop a single API endpoint
/api/submitthat accepts aPOSTrequest with the following JSON payload structure:
{
"name": "John Doe",
"email": "john.doe@example.com",
"message": "This is a test message"
}- Validate the data (ensure name', email and message are present).
- Database setup: Use Laravel migrations to create a table named
submissionswith columns forid,name,email,messageand timestamps (creayed_atandupdated_at). - Job Queue: Upon receiving the API request, the data should
not be immediately saved to the database. Instead, dispatch a Laravel job to process the data.
The job should perform the following tasks:
- Save the data to the
submissionstable in the database.
- Save the data to the
- Events: After the data is successfully saved to the database,
trigger a Laravel event named
SubmissionSaved. Attach a listener to this event that logs a message indicating a successful save, includingnameandemailof the submission. - Error handling: Implement error handling for the API to respond with appropriate messages
and status codes for the following scenarios:
- Invalid data input (e.g., missing required fields).
- Any errors that occur during the job processing.
- Documentation: Briefly document the following in a README file:
- Instructions on setting up the project and running migrations.
- A simple explanation of how to test the API endpoint.
- Write a simple test.