Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morzhanov/nodejs-http2-example
Simple NodeJS HTTP server examples (using core net module)
https://github.com/morzhanov/nodejs-http2-example
Last synced: 5 days ago
JSON representation
Simple NodeJS HTTP server examples (using core net module)
- Host: GitHub
- URL: https://github.com/morzhanov/nodejs-http2-example
- Owner: morzhanov
- Created: 2020-11-22T19:14:29.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-24T16:07:46.000Z (about 4 years ago)
- Last Synced: 2024-11-08T00:52:39.218Z (about 2 months ago)
- Language: TypeScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nodejs-http2-example
Simple NodeJS HTTP2 server example (using core http2 module)
## To start app run
```bash
npm run start
```Application accepts connections on 127.0.0.1:8443
## Description
Example Users CRUD app using NodeJS `http2` module.
Endpoints:
- `POST /users` - create a user
- `GET /users` - get all users
- `GET /users/{userId}` = get a single user
- `DELETE /users/{userId}` - delete user
- `PUT /users/{userId}` - update userAlso, this example contains simple Static Server and HTTP2 Server Push example.
## Performing requests
In order to perform request create `client_cert.pem` and `client_key.pem`.
To perform request run:```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
https://localhost:8443
```### General Request
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
https://localhost:8443/index.html
```### Server Push Request
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
https://localhost:8443/push.html
```### CRUD Request
#### GET all
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
https://localhost:8443/users
```#### GET one
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
https://localhost:8443/users/
```#### POST create one
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
-X POST \
-d '{"id": "some-id", "name": "some-name"}' \
https://localhost:8443/users
```#### DELETE one
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
-X DELETE \
https://localhost:8443/users/
```#### PUT update one
```bash
curl -v --http2 \
--cert ./client_cert.pem \
--key ./client_key.pem \
--pass \
-k \
-X POST \
-d '{"id": "some-id", "name": "some-name"}' \
https://localhost:8443/users/
```## TLS
In order to run server we should create `cert.crt` and `key.key` files and put those files under `./src/tls/` folder