Skip to content

Repository contains code that shows how one can make connection between a React app (frontend), with Laravel API (backend).)

License

Notifications You must be signed in to change notification settings

bartekgdev/react-and-laravel-api-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to use Laravel API in React

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.

Table of Contents

  1. Installation
  2. Running the Application
  3. Project Structure
  4. API Overview
  5. How the API Works
  6. Contributing
  7. License

Installation

Follow these steps to set up the project:

  1. 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
  2. Install Dependencies for Laravel Backend:
    Navigate to the backend directory and install dependencies using Composer:

    cd my-laravel-api
    composer install
  3. 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
  4. Install Dependencies for React Frontend:
    Navigate to the frontend directory and install dependencies using npm:

    cd my-react-app
    npm install

Running the Application

  1. Start Laravel Server:
    In the my-laravel-api directory, start the Laravel development server:

    php artisan serve
  2. Start React Development Server:
    In the my-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.


Project Structure

Backend (Laravel)

  • Routes: API routes are defined in routes/api.php.
  • Controllers: Backend logic resides in app/Http/Controllers. ¡

Frontend (React)

  • App: React app is located in the src/App.js file. That's where the API call is made.

API Overview

This project provides a simple API for sending and receiving data between the React frontend and Laravel backend.

Endpoints

  • GET /api/data
    Returns a random string generated by the backend.

Contributing

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.


License

This project is licensed under the MIT License.

About

Repository contains code that shows how one can make connection between a React app (frontend), with Laravel API (backend).)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published