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.
- Node.js
- JavaScript
GET
/users?search={username or user email}
(returns all users or filtered users)
name type data type description search optional string User email or name to filter
http code content-type response 200
application/json
JSON containing all users or only filtered users
curl -X GET -H "Content-Type: application/json" http://localhost:3333/users
POST
/users
(creates a new user)
name type data type description required string User email name required string User name
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 -X POST -H "Content-Type: application/json" --data @post.json http://localhost:3333/users
PUT
/users/{id}
(edits a user)
name type data type description id required int User unique identifier
name type data type description required string Email of the user to be edited name required string Name of the user to be edited
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 -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:3333/users/id
DELETE
/users/{id}
(deletes a user)
name type data type description id required int User unique identifier
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 -X DELETE -H "Content-Type: application/json" http://localhost:3333/users/id
- 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
- 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.