Giter Club home page Giter Club logo

blog-api-node's Introduction

Blog API


Clique aqui para ver a versão em Português.

💻 Project

The project consists of a simple API for authors and their posts. It allows actions such as creating, listing, editing, and deleting posts. Posts can be marked as published or not.

🚀 Technologies

  • Node.js
  • Express
  • TypeScript
  • Prisma ORM

Endpoints

Listing Users and Posts

GET /users (returns all users)
Parameters

None

Responses
http code content-type response
200 application/json JSON containing all users
cURL Example
 curl -X GET -H "Content-Type: application/json" http://localhost:4000/users
GET /posts (returns all posts)
Parameters

None

Responses
http code content-type response
200 application/json JSON containing all blog posts
cURL Example
 curl -X GET -H "Content-Type: application/json" http://localhost:4000/posts
GET /post/{id} (returns the post with the specified ID)
Parameters
name type data type description
id required string The unique identifier of the post
Responses
http code content-type response
200 application/json JSON containing the post with the specified ID
cURL Example
 curl -X GET -H "Content-Type: application/json" http://localhost:4000/post/id

Creating a New User or Post

POST /post (creates a new post)
Parameters
name type data type description
title required string Title of the post
body required string Content of the post
author required int Unique identifier of the post author
Responses
http code content-type response
201 text/plain;charset=UTF-8 Post created successfully
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
cURL Example
 curl -X POST -H "Content-Type: application/json" --data @post.json http://localhost:4000/posts
POST /users (creates a new user)
Parameters
name type data type description
email required string User's email
name required string User's name
age optional int User's age
Responses
http code content-type response
201 text/plain;charset=UTF-8 User created successfully
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
cURL Example
 curl -X POST -H "Content-Type: application/json" --data @user.json http://localhost:4000/users

Editing a Post

PUT /post/{id} (edits a post)
Parameters
name type data type description
id required int Unique identifier of the post
Responses
http code content-type response
200 text/plain;charset=UTF-8 Returns the edited post
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
cURL Example
 curl -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:4000/post/id

Deleting a Post

DELETE /post/{id} (deletes a post)
Parameters
name type data type description
id required int Unique identifier of the post
Responses
http code content-type response
200 text/plain;charset=UTF-8 Returns a status true
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
cURL Example
 curl -X DELETE -H "Content-Type: application/json" http://localhost:4000/post/id

📄 How to Use

  • Clone this repository:
  $ git clone https://github.com/luc-ribeiro/blog-api-node.git
  • Install the dependencies:
  # with npm
  $ npm install

  # with yarn
  $ yarn install
  • Create a .env file in the root of the project following the variables defined in the .env.example file.

  • Run the command:

  # with npm
  $ npm start

  # with yarn
  $ yarn start
  • Access the project at localhost:[PORT DEFINED IN THE .ENV FILE]

blog-api-node's People

Contributors

luc-ribeiro 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.