Skip to content

DeveloperJosh/Rust-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust REST API

This is a RESTful API built with Rust, designed to handle posts, likes, and user authentication features including logins and sign-ups. The service uses PostgreSQL for efficient data storage and retrieval, supporting scalability as user interactions increase.

Features

  • Posts Management: Create, update, and delete posts.
  • Likes: Users can like posts.
  • User Authentication: Support for user logins and sign-ups.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You will need PostgreSQL installed on your machine. Follow the instructions for your operating system:

Ubuntu

sudo apt update
sudo apt install postgresql postgresql-contrib

macOS

brew install postgresql
brew services start postgresql

Windows

Download and install PostgreSQL from the official website.

Rust Installation

Ensure you have Rust installed:

rustup update
rustup install stable

Database Setup

  1. Start PostgreSQL service:

    sudo service postgresql start  # Ubuntu
    brew services start postgresql  # macOS
  2. Create a new PostgreSQL database:

    sudo -u postgres psql  # Ubuntu
    psql postgres  # macOS or Windows (if added to PATH)

    In the PostgreSQL shell:

    CREATE DATABASE your_database_name;
    \q

    Making Tables

    CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    username TEXT NOT NULL UNIQUE,
    email TEXT NOT NULL UNIQUE,
    password_hash TEXT NOT NULL,
    created_at TIMESTAMP NOT NULL
    );
    
    CREATE TABLE tweets (
    id SERIAL PRIMARY KEY,
    content TEXT NOT NULL,
    likes INTEGER,
    created_at TIMESTAMP NOT NULL
    );
    
  3. Set up your .env file with the PostgreSQL connection string:

    DATABASE_URL=postgres://username:password@localhost/your_database_name
    JWT_SECRET=your_jwt_secret

Running the Application

Clone the repository and navigate to the project directory:

git clone https://github.com/your_username/your_project.git
cd your_project

Run the application:

cargo run

This will start the server on http://localhost:8080.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A restful api in RUST?!?!?!?!?!??!?!?!?

Topics

Resources

Stars

Watchers

Forks

Languages