Skip to content

πŸͺ Starter repository for an Express app using Deta Base written in TypeScript and running on Deta Micros

License

Notifications You must be signed in to change notification settings

BetaHuhn/deta-express-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Deta Express Starter

Starter repository for a Express app using Deta Base written in TypeScript and running on Deta Micros


πŸ‘‹ Introduction

This is a demo/starter template for a simple TypeScript Express API runnning on Deta. It uses Deta Base as its database and deta-base-orm to structure and access it.

πŸš€ Get Started

Click "Use this template" on the GitHub website to create a new repository based on this template.

Clone the newly created repository and cd into it:

git clone https://github.com/<username>/deta-express-starter && cd $_

Install the dependencies:

npm install

Create a .env file and add your Deta project key:

DETA_PROJECT_KEY=<your project key>

Start the development server:

npm run dev

Deploy to Deta:

npm run deploy

πŸ“š Usage

The example consists of a simple REST API with two main resources, users and messages. Each message has a text and is sent from one user to another. Take a look at src/models/ to see how they are structured using deta-base-orm.

The API is served under /api/v1 with simple GET and POST endpoints at /api/v1/user and /api/v1/message. They both return JSON data in the following format:

{
    "status": 200,
    "message": "ok",
    "data": {}
}

Here is a list of all the endpoints:

User

POST /api/v1/user

Create a new user.

Payload:

{ "username": "username", "email": "email" }

GET /api/v1/user

Get all users.

Response:

{
    "status": 200,
    "message": "ok",
    "data": [
        {
            "username": "...",
            "email": "...",
            "key": "..."
        },
    ]
}

GET /api/v1/user/:key

Get a single user by its key.

Response:

{
    "status": 200,
    "message": "ok",
    "data": {
        "username": "...",
        "email": "...",
        "key": "..."
    }
}

Message

POST /api/v1/message

Create a new message.

Payload:

{ "text": "Hello World", "from": "user key", "to": "user key" }

GET /api/v1/message

Get all messages.

Response:

{
    "status": 200,
    "message": "ok",
    "data": [
        {
            "text": "...",
            "from": "...",
            "to": "...",
            "key": "..."
        },
    ]
}

GET /api/v1/message/:key

Get a single message by its key.

Response:

{
    "status": 200,
    "message": "ok",
    "data": {
        "text": "...",
        "from": "...",
        "to": "...",
        "key": "..."
    }
}

GET /api/v1/message/sent/:key

Get all messages sent from a user.

Response:

{
    "status": 200,
    "message": "ok",
    "data": [
        {
            "text": "...",
            "from": "...",
            "to": "...",
            "key": "..."
        },
    ]
}

GET /api/v1/message/received/:key

Get all messages received by a user.

Response:

{
    "status": 200,
    "message": "ok",
    "data": [
        {
            "text": "...",
            "from": "...",
            "to": "...",
            "key": "..."
        },
    ]
}

Checkout /src/router/api to see how they are implemented.

❔ About

This project was developed by me (@betahuhn) in my free time. If you want to support me:

Donate via PayPal

ko-fi

πŸ“„ License

Copyright 2021 Maximilian Schiller

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

About

πŸͺ Starter repository for an Express app using Deta Base written in TypeScript and running on Deta Micros

Topics

Resources

License

Stars

Watchers

Forks