node-api/README.md

55 lines
1.1 KiB
Markdown
Raw Normal View History

2023-12-24 23:02:03 +00:00
# Basic API server (Node.js + Express.js, TypeScript version)
2023-12-23 16:25:57 +00:00
## Abstract
2023-12-24 23:02:03 +00:00
A basic functional template for creating an API server using Node.js + Express.js using TypeScript.
2023-12-24 03:17:09 +00:00
## Test
The template is functional and you can test it using HTTPie, curl or Postman.
### Start the API server
2023-12-24 03:28:29 +00:00
```
2023-12-24 03:32:34 +00:00
$>npm run dev
2023-12-24 23:02:03 +00:00
```
Response
2023-12-24 03:17:09 +00:00
2023-12-24 23:12:27 +00:00
> api_srvr@1.0.0 dev<br>
> nodemon ./src/apisrvr.ts<br>
><br>
> [nodemon] 3.0.2<br>
> [nodemon] to restart at any time, enter `rs`<br>
> [nodemon] watching path(s): *.*<br>
> [nodemon] watching extensions: ts,json<br>
> [nodemon] starting `ts-node ./src/apisrvr.ts`<br>
> Basic API Server listening on Port:3000<br>
> TypeScript Version<br>
> Press Ctrl-C to exit<br>
2023-12-24 03:17:09 +00:00
2023-12-24 03:28:29 +00:00
### Test with HTTPie
Using another terminal, run the following wommand
2023-12-24 03:17:09 +00:00
2023-12-24 03:32:34 +00:00
```
$>http localhost:3000/
2023-12-24 23:02:03 +00:00
```
Response
2023-12-24 23:12:27 +00:00
> HTTP/1.1 200 OK<br>
> Connection: keep-alive<br>
> Content-Length: 16<br>
> Content-Type: text/html; charset=utf-8<br>
> Date: Sun, 24 Dec 2023 03:23:55 GMT<br>
> ETag: W/"10-bZZA7c+e/eSluV2PjdNck3t/8tA"<br>
> Keep-Alive: timeout=5<br>
> X-Powered-By: Express
> <br>
> Main page loaded
>
> $>
2023-12-24 23:02:03 +00:00