Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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 user

Also, 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