This is a simple Laravel API that provides weather information for a given city. The API uses JWT for authentication and interacts with a third-party weather service to fetch the weather data.
- User authentication with JWT
- Fetch weather information for a given city
The API has the following routes:
- POST /v1/auth/login: Authenticate a user and generate a JWT
- POST /v1/auth/user-profile: Fetch the authenticated user's profile
- GET /v1/weather/{city}: Fetch the weather information for a given city
The API has two main controllers:
- AuthController: Handles user authentication and profile fetching
- WeatherController: Fetches weather information for a given city
The API uses several services to handle business logic:
- AuthService: Handles user authentication
- WeatherService: Interacts with a third-party weather service to fetch weather data
- RapidApiService: Handles interactions with the RapidAPI service
The API includes tests for user authentication and weather fetching.
To install the API, follow these steps:
- Clone the repository
- Run
composer install
to install the necessary dependencies - Copy
.env.example
to.env
and fill in your database and RapidAPI credentials - Run
php artisan jwt:secret
to update .env with jwt secret - Run
php artisan migrate
to create the necessary database tables - Run
php artisan db:seed --class=UserSeeder
to seed the database with test data - Run
php artisan serve
to start the server
To use the API, send a POST request to /v1/auth/login
with the following credentials to authenticate and receive a JWT:
- Email: test@test.com
- Password: testtest
Include this JWT in the Authorization header of your requests to the /v1/weather/{city}
endpoint to fetch weather information.
To run the tests, use the following command:
php artisan test
This project is licensed under the MIT License.