Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmcdo29/nest-content-negotiation
A small server to show off a content negotiation interceptor
https://github.com/jmcdo29/nest-content-negotiation
Last synced: 23 days ago
JSON representation
A small server to show off a content negotiation interceptor
- Host: GitHub
- URL: https://github.com/jmcdo29/nest-content-negotiation
- Owner: jmcdo29
- Created: 2020-04-29T18:11:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T02:21:02.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T20:21:51.965Z (about 1 month ago)
- Language: TypeScript
- Size: 2.3 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
[travis-url]: https://travis-ci.org/nestjs/nest
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
[linux-url]: https://travis-ci.org/nestjs/nest
A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
## Description
There is a [ContentInterceptor](./src/content.interceptor.ts) that has a switch clause in the `map` operation of outgoing requests that properly sets the `Content-Type` header and serializes the data properly. Using the following commands, you can see what responses are given
### Start the Server
`git clone`
`npm i` or `yarn`
`run script: start` or `run script: start:dev`### Making calls
I use [Curl]() for making calls from my terminal, but postman will work too.
```sh
# plain text
curl http://localhost:3000 -H 'Accept: text/plain'# response
hello=world&name=test## xml
curl http://localhost:3000 -H 'Accept: application/xml'# response
world
test# json
# Note: this is also the default
curl http://localhost:3000 -H 'Accept: application/json'# response
{"hello":"world","name":"test"}
```You could add in other serializers as well, but I this should be enough to give an idea of what's going on.