loopbackio / loopbackio/loopback-next

Add REST response serializer, transparent content negotiation

Aperta
#6,275 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature help wanted major REST
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

## Suggestion

We should...
1. Provide an extension point to allow contribution of response deserializers
2. Process automatic content negotiation to use the correct deserializer, similar to `BodyParser`.

## Use Cases

Currently, there is only support for `BodyParser`s that de-serialize REST request bodies to JSON. This means the Request-Response Lifecycle cannot be fully covered by a `BodyParser`, and requires lb4 users to manually serialize the controllers' response and prematurely return the response using `res.end` (see: #5168).

## Examples

For the extension point, a serializer could implement the following design:

```typescript
interface ResponseSerializer {
isSupported = (contentType: string) => boolean;
serialize = (body: any) => string
}
```

If need be, we can create a higher-level class the merges role of the existing `BodyParser` and the new `ResponseSerializer`. This has the benefit of requiring a single class to implement both serialization and deserialization. However, this adds complication to the LB4 design, and should probably be considered **after** implementing the `ResponseSerializer` extension point, so that the separation between the lower-level and higher-level extension points are clear. In the long-term, we may deprecate the lower level `BodyParser` and `ResponseSerializer` in favour of the "unified (de-)serializer".

## Acceptance criteria

TBD - will be filled by the team.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando il punto di estensione esistente di BodyParser e il Request-Response Lifecycle, quindi confronta l’interfaccia ResponseSerializer proposta con i requisiti di negoziazione dei contenuti. I criteri di accettazione dell’issue sono ancora TBD, quindi il completamento richiede criteri concordati che coprano il contributo del serializer, la selezione automatica e la gestione della risposta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.