Giter Site home page Giter Site logo

gouserrestapi's Introduction

Go User RestAPI

A minimalistic REST API microservice built with Go for user authentication.

Overview

This project is a lightweight microservice focused on user authentication. Built with Go and leveraging its standard library, it serves as a demonstration of creating RESTful APIs in Go with a focus on user registration, login, and token-based authentication.

Features

  • User Registration: Allows new users to create an account.
  • User Login: Existing users can log in and receive a token for authenticated routes.
  • Token-based Authentication: Utilizes JWT (JSON Web Tokens) for secure and stateless authentication.
  • In-memory Store: A temporary storage solution to hold user data.
  • Profile Management: Allows users to view, update, and delete their profiles.

Getting Started

Prerequisites

  • Go (version 1.xx or newer)

Environment Variables

Before running the project, you need to set the following environment variables:

  • HOST: Host address for the server (e.g., localhost or 0.0.0.0). Default: localhost.
  • PORT: Port on which the server will listen (e.g., 8080). Default: 8080.
  • JWT_KEY: Secret key for generating and validating JWT tokens. Ensure it's a strong, unique key. No default.
  • ALLOWED_ORIGINS: Comma-separated list of allowed origins for CORS. Default: * (allow all origins).

Running the Project

  1. Clone the repository:

    git clone https://github.com/mark-c-hall/GoUserRestAPI.git
    
  2. Navigate to the project directory:

    cd GoUserRestAPI
    
  3. Run the server:

    go run main.go
    

The API will start and listen on the configured port, e.g., :8080.

Endpoints

  • POST /register: Register a new user.
  • POST /login: Login and receive a token.
  • POST /logout: Logout the current user and invalidate the token.
  • GET /profile: Retrieve the profile information of the authenticated user.
  • POST /profile/update: Update user profile details.
  • POST /profile/delete: Delete the user's profile.
  • GET /health: Health check endpoint returning a 200 OK status, useful for monitoring and service checks.

Note: Ensure that the appropriate HTTP methods (GET, POST, etc.) are used when making requests to these endpoints.

Future Improvements

  • Replace the in-memory store with a persistent database.
  • Add user profile and settings management features.
  • Implement rate-limiting and additional security measures.

Contributing

While this is a small project for educational purposes, contributions or feedback are welcome. Feel free to open an issue or submit a pull request.

License

This project is open-source and available under the MIT License.

Acknowledgements

gouserrestapi's People

Contributors

mark-c-hall avatar

Watchers

 avatar  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.