This project is a simple News application where users can view, create, update, and delete news articles. The application is built using Laravel for the mock up API and React with Vite for the frontend.
To run the backend of the application, which is built with Laravel, follow the steps below:
Make sure that PHP and Composer are installed on your machine. You can download them from the following links:
Clone the repository to your local machine:
git clone git@github.com:QuantMis/news-article-assignment.git
cd news-apiRun the following command to install Laravel's dependencies using Composer:
composer installCopy the .env.example file to create a new .env file:
cp .env.example .envRun the following command to generate an application key:
php artisan key:generateRun the following command to set up the database tables:
php artisan migrateRun the following command to set up the database tables:
php artisan db:seed NewsSeeder
`
### 7. Serve the Laravel Application
Run the following command to start the Laravel development server:
```bash
php artisan serveBy default, the server will run on http://localhost:8000.
To run the frontend of the application, which is built with React and Vite, follow the steps below:
Make sure that Node.js and npm are installed on your machine. You can download them from the following link:
Run the following command to install the frontend dependencies:
npm installRun the following command to start the Vite development server:
npm run devThe frontend application will be available at http://localhost:5173.
Here are the main API endpoints for the backend:
- GET /api/news - Retrieve all news articles.
- GET /api/news/{id} - Retrieve a single news article by ID.
- POST /api/news - Create a new news article.
- PUT /api/news/{id} - Update an existing news article by ID.
- DELETE /api/news/{id} - Delete a news article by ID.
app/Http/Controllers/NewsController.php- Handles CRUD operations for news.app/Models/News.php- News model.routes/api.php- API routes for news endpoints..env- Environment configuration for the backend (database, app key, etc.).
src/components/NewsList.tsx- Displays a list of news articles.src/components/NewsDetail.tsx- Displays the details of a single news article.src/components/NewsForm.tsx- Form for creating and editing news articles.src/types/news.ts- Type definition for the news articles..env- Environment configuration for the frontend (API URL).vite.config.ts- Vite configuration file.