Skip to content

Project that uses Node.js streams to create a simple application, with the purpose of practicing Node.js fundamentals. A simple API was also created, without the use of frameworks.

Notifications You must be signed in to change notification settings

luc-ribeiro/streams-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Streams Node.js

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

💻 Project

This project was created during the Node.js course by Rocketseat.

The project consists of creating a simple API using only Node.js without frameworks. The goal is to practice the fundamentals of this technology and address the concept of streams.

Streams are a way to read and process files while they are being sent to the server. Every input and output port in Node.js is a stream. It's possible to process large files while they are being sent to the server.

🚀 Technologies

  • Node.js
  • JavaScript

Endpoints

Listing Users

GET /users?search={username or user email} (returns all users or filtered users)
Parameters
name type data type description
search optional string User email or name to filter
Responses
http code content-type response
200 application/json JSON containing all users or only filtered users
cURL Example
 curl -X GET -H "Content-Type: application/json" http://localhost:3333/users

Creating a New User

POST /users (creates a new user)
Parameters
name type data type description
email required string User email
name required string User name
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 @post.json http://localhost:3333/users

Editing a User

PUT /users/{id} (edits a user)
Parameters
name type data type description
id required int User unique identifier
Body
name type data type description
email required string Email of the user to be edited
name required string Name of the user to be edited
Responses
http code content-type response
204 text/plain;charset=UTF-8 User changed successfully
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:3333/users/id

Deleting a User

DELETE /users/{id} (deletes a user)
Parameters
name type data type description
id required int User unique identifier
Responses
http code content-type response
204 text/plain;charset=UTF-8 User deleted successfully
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:3333/users/id

📄 How to Use

  • Clone this repository:
  $ git clone https://github.com/luc-ribeiro/streams-nodejs.git
  • Run the command:
  # with npm
  $ npm run dev

  # with yarn
  $ yarn dev
  • The project will run at localhost:3333

Testing Streams

  • Run the command in the project root:
  $ node streams/stream-http-server.js
  $ node streams/fake-upload-to-http-stream.js

View the gradual sending of a count from 1 to 5 in the stream-http-server.js terminal.

About

Project that uses Node.js streams to create a simple application, with the purpose of practicing Node.js fundamentals. A simple API was also created, without the use of frameworks.

Topics

Resources

Stars

Watchers

Forks