Giter Site home page Giter Site logo

blog-server-with-dart's Introduction

Blog Server with Dart

Binding a REST of Blog with Dart (Spry + Prisma)

Introduction

This is a template repository that is a demonstration of Dart server-side application development. It is intended to guide you on how to use Dart to build a server-side application that is well maintained and has a clear code structure.

These technology stacks are required:

Getting Started

First, download the code of this warehouse to your local:

git clone https://github.com/medz/blog-server-with-dart && cd blog-server-with-dart

Then, install the dependencies:

dart pub get

Configuration database

Open the .env file and modify DATABASE_URL to your database connection address.

DATABASE_URL="postgresql://user:password@host:port/database?schema=public"

Generate Prisma client

npx prisma generate

Note: The npx command comes from Node.js. Since Prisma CLI is developed based on Node.js, it requires Node.js environment. For more information please see ๐Ÿ‘‰ Prisma Client Dart - Install

Run server

dart run server.dart

Project Structure

- controllers/ # Controllers
    - auth_controller.dart # Auth controller
    - post_controller.dart # Post controller
    - user_controller.dart # User controller
- dtos/ # DTOs
- exceptions/ # Exceptions & Exception filters
    - convert_json_exception_filter.dart # Convert Json Exception Filter
    - unauthorized_exception.dart # Unauthorized Exception
- extensions/ # Dart extensions helpers
    - request+access_token.dart # Request extension for access token `request.accessToken`
    - request+prisma.dart # Request extension for prisma client `request.prisma`
    - request+user.dart # Request extension for user `request.user`
- middlewares/ # Middlewares
    - authenticator.dart # Authenticator middleware, Authenticate user by access token
    - prisma_middlewares.dart # Prisma middlewares, Inject prisma client to request
- prisma/ # Prisma configuration (Schema, generated client)
    - schema.prisma # Prisma schema
    - generated_dart_client/ # Generated Prisma client
- resources/ # API resources
    - auth_resource.dart # Auth resource
    - post_resource.dart # Post resource
    - user_resource.dart # User resource
    - category_resource.dart # Category resource
    - profile_resource.dart # Profile resource
    - resource.dart # Base resource
- .env # Environment variables, Configuration database
- server.dart # Server entry

APIs

Auth

Login

POST /login

Content-Type: application/json

{
    "email": "<email>",
    "password": "<password>"
}

Register

POST /register

Content-Type: application/json

{
    "name": "<name>",
    "email": "<email>",
    "password": "<password>"
}

Logout

GET /logout

Users

Get Users

GET /users

Search params:

| Name | Required | Default | Description | | take | false | 10 | The number of records to take | | skip | false | 0 | The number of records to skip |

show User

GET /users/:id

Update User

PATCH /users/:id

Content-Type: application/json

{
    "name": "<optional name>",
    "email": "<optional email>",
    "password": "<optional password>"
}

Show user's profile

GET /users/:id/profile

Posts

Get Posts

GET /posts

Search params:

| Name | Required | Default | Description | | take | false | 10 | The number of records to take | | skip | false | 0 | The number of records to skip |

Show Post

GET /posts/:id

Create Post

POST /posts

Content-Type: application/json

{
    "categoryId": <CategoryId>,
    "title": "<title>",
    "contents": "<contents>",
    "description": "<Optional description>"
}

Update Post

PATCH /posts/:id

Content-Type: application/json

{
    "title": "<title>",
    "contents": "<contents>",
    "description": "<Optional description>",
    "published": <true or false>
}

Delete Post

DELETE /posts/:id

blog-server-with-dart's People

Contributors

medz avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

blog-server-with-dart's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

bun
package.json
  • prisma ^5.8.1
pub
pubspec.yaml
  • orm 4.1.0
  • spry ^3.1.2
  • lints ^4.0.0
  • test ^1.24.0
  • dart ^3.2.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.