Giter VIP home page Giter VIP logo

jonnrib / h-server Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18 KB

hanami-server is the backend API of the Hanami project. It provides CRUD operations for posts, using Entity Framework Core and SQLite. The API includes JWT-based authentication and follows RESTful principles. Docker support is included for easy deployment. Designed with clean architecture, it ensures maintainability and scalability.

License: MIT License

C# 98.44% Dockerfile 1.56%

h-server's Introduction

HanamiAPI

HanamiAPI is a robust and scalable API designed to manage user authentication, posts, and access control for a content management system. Built with ASP.NET Core, Entity Framework, and JWT for secure authentication, this project aims to provide a solid foundation for web applications requiring user management and content publishing features.

Table of Contents

Project Overview

Hanami API is a robust and scalable web service that allows users to manage posts. It is built with a clean architecture to ensure ease of maintenance and use.

Features

  • CRUD operations for posts
  • RESTful endpoints
  • Database migration management
  • Dependency injection
  • Containerization with Docker
  • User Authentication and Authorization: Secure registration, login, and logout functionalities with JWT-based authentication.
  • Role-Based Access Control: Manage different user roles and permissions to ensure secure access to resources.
  • Asynchronous Processing: Improved performance and reliability with asynchronous operations.
  • Entity Framework Integration: Utilize Entity Framework for efficient database management and migrations.

Technology Stack

  • Backend: ASP.NET Core, Entity Framework Core
  • Authentication: JWT (JSON Web Tokens)
  • Database: SQL Server (or any EF Core compatible database)
  • DevOps: Docker for containerization, GitHub Actions for CI/CD
  • SQLite (Database)
  • Swagger (API Documentation)

Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

NuGet Package Installation

Using the Visual Studio Interface

  1. Open the NuGet Package Manager in Visual Studio:

    • Right-click on your project in the Solution Explorer.
    • Select "Manage NuGet Packages...".
  2. Install the following packages:

    • Microsoft.EntityFrameworkCore.Sqlite
    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Tools
    • Swashbuckle.AspNetCore

Using the Package Manager Console

  1. Open the Package Manager Console:

    • Go to "Tools" > "NuGet Package Manager" > "Package Manager Console".
  2. Execute the following commands:

    Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 8.0.5
    Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 8.0.5
    Install-Package Microsoft.EntityFrameworkCore.Tools -Version 8.0.5
    Install-Package Swashbuckle.AspNetCore -Version 6.6.2

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/hanami-api.git
    cd hanami-api
  2. Install the dependencies:

    dotnet restore

Configuration

Ensure you have an appsettings.json file in the root of the project with the following content:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=app.db"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Running the Application

  1. Apply the database migrations:

    dotnet ef database update
  2. Run the application:

    dotnet run
  3. Access the API documentation at http://localhost:8080/swagger.

Recommendation for Committing Data in app.db

To ensure changes to the app.db file are not included in future commits, execute the following command:

git update-index --assume-unchanged app.db

This command makes Git ignore future changes to the app.db file in your local repository.

API Endpoints

Create a Post

  • URL: /api/posts

  • Method: POST

  • Request Body:

    {
      "title": "Post Title",
      "content": "Post content"
    }
  • Response:

    {
      "id": 1,
      "title": "Post Title",
      "content": "Post content",
      "createdAt": "2024-05-27T12:34:56Z"
    }

List All Posts

  • URL: /api/posts

  • Method: GET

  • Response:

    [
      {
        "id": 1,
        "title": "Post Title",
        "content": "Post content",
        "createdAt": "2024-05-27T12:34:56Z"
      }
    ]

Get a Specific Post

  • URL: /api/posts/{id}

  • Method: GET

  • Response:

    {
      "id": 1,
      "title": "Post Title",
      "content": "Post content",
      "createdAt": "2024-05-27T12:34:56Z"
    }

Update a Post

  • URL: /api/posts/{id}

  • Method: PUT

  • Request Body:

    {
      "title": "Updated Title",
      "content": "Updated content"
    }
  • Response:

    {
      "id": 1,
      "title": "Updated Title",
      "content": "Updated content",
      "createdAt": "2024-05-27T12:34:56Z",
      "updatedAt": "2024-05-27T12:45:00Z"
    }

Delete a Post

  • URL: /api/posts/{id}
  • Method: DELETE
  • Response: 204 No Content

Database Migrations

To add a new migration:

dotnet ef migrations add MigrationName

To update the database:

dotnet ef database update

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Make your changes.
  4. Commit your changes (git commit -m "Add some feature").
  5. Push to the branch (git push origin feature/YourFeature).
  6. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

h-server's People

Contributors

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