Giter Club home page Giter Club logo

blog's Introduction

Blog challange

This project holds a sample of an application that runs on express and typescript with a mongodb instance in a docker container

How to run

  1. Make sure docker and npm are installed
  2. copy .env.example to .env file and add the desired values
  3. run npm i
  4. run npm run docker:up
  5. run npm run dev

At this point you should be able to hit the api using postman, insomina or curl

Endpoints

GET /api/posts/

This Endpoint will return all posts and its comments

curl --location 'http://localhost:3000/api/posts'

Example respose:

[
    {
        "_id": "66847fb6f7ae6e081f994e77",
        "title": "first post",
        "text": "this is my first post",
        "createdAd": "2024-07-02T22:31:18.022Z",
        "comments": [
            {
                "text": "comments ",
                "createdAt": "2024-07-02T22:31:30.558Z",
                "_id": "66847fc2f7ae6e081f994e7b"
            },
            {
                "text": "another comments ",
                "createdAt": "2024-07-02T22:32:03.536Z",
                "_id": "66847fe38137429d2da15010"
            }
        ],
        "__v": 0
    }
]

POST api/posts

This endpoint will add an post (if it not already exists) to the mongodb instance

It expects an object of type

{
    "title": "first post",
    "text": "this is my first post"
}
curl --location 'http://localhost:3000/api/posts' \
--header 'Content-Type: application/json' \
--data '{
    "title": "first post",
    "text": "this is my first post"
}'

Response will be either StatusCode === 204 indicating a succesful insert or Statuscode === 409 indicating a conflict (unsucesful) insert

GET /api/posts/:id

This endpoint will return a give post with its comments

curl --location 'http://localhost:3000/api/posts/:id'

Example response:

{
    "_id": "66847fb6f7ae6e081f994e77",
    "title": "first post",
    "text": "this is my first post",
    "createdAd": "2024-07-02T22:31:18.022Z",
    "comments": [
        {
            "text": "comments ",
            "createdAt": "2024-07-02T22:31:30.558Z",
            "_id": "66847fc2f7ae6e081f994e7b"
        },
        {
            "text": "another comments ",
            "createdAt": "2024-07-02T22:32:03.536Z",
            "_id": "66847fe38137429d2da15010"
        }
    ],
    "__v": 0
}

POST api/posts/:id/comments

This endpoint will add comments object to a given post

It expects an object of type

{
    "text": "your comment here"
}

Response will be either StatusCode === 200 indicating a succesful insert or Statuscode === 400 indicating a post not found/unsucesful insert

blog's People

Contributors

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