Giter VIP home page Giter VIP logo

blog_api's Introduction

React Blog API

This is a simple RESTful API built with Express.js and MySQL to support a blog application developed using React.

Prerequisites

  • Node.js and npm should be installed on your machine.
  • MySQL server should be installed and running.

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/react-blog-api.git
  2. Navigate to the project directory:

    cd blog_api
  3. Install the dependencies:

    npm install
  4. Set up the MySQL database:

    • Create a new database in your MySQL server.

    • Update the database connection details in app.js file:

      const connection = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "",
        database: "your_database_name",
      });
  5. Start the server:

    npm start

    The server will run on http://localhost:5000.

API Endpoints

  • GET /: Get all users.
  • GET /posts: Get all blog posts.
  • GET /comments: Get all comments.
  • GET /posts/:id: Get a specific blog post by ID.
  • GET /comments/:id: Get comments for a specific blog post by ID.
  • POST /comments/:id: Add a new comment to a blog post.
  • POST /posts: Create a new blog post.
  • POST /users: Register a new user.
  • POST /login: Authenticate a user.
  • DELETE /posts/:id: Delete a blog post.
  • DELETE /comments/:id: Delete a comment.
  • PUT /posts/:id: Update a blog post.
  • PUT /comments/:id: Update a comment.

Database Schema

The API assumes the following database schema:

  • users table:

    • id (INT): User ID (Primary Key)
    • username (VARCHAR): User's username
    • email (VARCHAR): User's email
    • password (VARCHAR): User's password
    • created_at (TIMESTAMP): User creation timestamp
  • posts table:

    • id (INT): Post ID (Primary Key)
    • title (VARCHAR): Post title
    • content (TEXT): Post content
    • author_id (INT): Author's User ID (Foreign Key referencing users table)
    • created_at (TIMESTAMP): Post creation timestamp
  • comments table:

    • id (INT): Comment ID (Primary Key)
    • content (TEXT): Comment content
    • post_id (INT): Post ID (Foreign Key referencing posts table)
    • author_id (INT): Author's User ID (Foreign Key referencing users table)
    • created_at (TIMESTAMP): Comment creation timestamp

License

This project is licensed under the MIT License.

Feel free to customize the README file as per your project's specific details and requirements.

blog_api's People

Contributors

lotfijb avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.