This project demonstrates how to integrate a React frontend with a Laravel backend using an API. The setup includes basic functionality for sending and receiving data between the two applications.
- Installation
- Running the Application
- Project Structure
- API Overview
- How the API Works
- Contributing
- License
Follow these steps to set up the project:
-
Clone the Repository:
Clone this repository to your local machine:git clone https://github.com/bartekgdev/react-and-laravel-api-example cd react-and-laravel-api-example
-
Install Dependencies for Laravel Backend:
Navigate to the backend directory and install dependencies using Composer:cd my-laravel-api composer install
-
Set Up Laravel Environment:
Copy the.env.example
file to.env
and configure your database and other settings:cp .env.example .env php artisan key:generate
-
Install Dependencies for React Frontend:
Navigate to the frontend directory and install dependencies using npm:cd my-react-app npm install
-
Start Laravel Server:
In themy-laravel-api
directory, start the Laravel development server:php artisan serve
-
Start React Development Server:
In themy-react-app
directory, start the React development server:npm start
The React application should now be accessible in your browser, typically at
http://localhost:3000
.
- Routes: API routes are defined in
routes/api.php
. - Controllers: Backend logic resides in
app/Http/Controllers
. ¡
- App: React app is located in the
src/App.js
file. That's where the API call is made.
This project provides a simple API for sending and receiving data between the React frontend and Laravel backend.
- GET /api/data
Returns a random string generated by the backend.
If you'd like to contribute to this project, feel free to fork the repository, create a feature branch, and submit a pull request. For major changes, please open an issue first to discuss what you'd like to change.
This project is licensed under the MIT License.