Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        


Nest Logo

[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.



NPM Version
Package License
NPM Downloads
Travis
Linux
Coverage
Gitter
Backers on Open Collective
Sponsors on Open Collective



## 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.