Skip to content

SanjayDevTech/nodejs-simple-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejs-simple-rest-api

Deployment:

  • Docker build
  • Deploy to heroku with ENV VARIABLES (DB, URI)
  • DB = Mongodb database name
  • URI = Mongodb URI string in the format user@password:url

Models:

User Model:

data class User(
    val email: String,
    val name: String,
    val password: String?,
)

Post Model:

data class Post(
    val _id: String,
    val title: String,
    val content: String,
    val email: String,
    val created: Long,
    val updated: Long,
)

Request:

data class PostRequest(
    val content: String,
    val title: String,
    val email: String,
    val password: String
)

Response:

data class Response<out T>(
    val status: Boolean,
    val errorMessage: String,
    val value: T,
)

API

GET /auth

List all users

Response:

// List of users but without password field
val value: List<User>

GET /auth/:emailId

Check if the user with email exists

Response:

// true if user exists
val value: Boolean

POST /auth/login

Login with email and password

Request:

// only email & password (not name)
User

Response:

// User object with password to store in local db
val value: User

POST /auth/register

Register with email, name and password

Request:

User

Response:

// email is returned back
val value: String

GET /post

List all posts available, if email given list all posts published by that user

Query Params:

// user email optional
val email: String

Response:

val value: List<Post>

GET /post/:postId

Returns the post by id

Response:

val value: Post

POST /post/:postId

Updates the existing post

Request:

PostRequest

Response:

// post id
val value: String

PUT /post

Publish new post

Request:

PostRequest

Response:

// post id
val value: String

DELETE /post/:postId

Delete the post

Request:

// current user
User

Response:

val value: Boolean