UNPKG

@anglr/rest

Version:

Angular module representing rest services

60 lines 2.26 kB
import { isBlank } from '@jscrpt/common'; import { ResponseType } from '../misc/enums'; /** * Middleware that is used for changing response type */ export class ProducesMiddleware { //######################### public static properties ######################### /** * String identification of middleware */ static { this.id = 'ProducesMiddleware'; } //######################### public methods - implementation of RestMiddleware ######################### /** * Runs code that is defined for this rest middleware, in this method you can modify request and response * @param this - Method is bound to RESTClient * @param id - Unique id that identifies request method * @param target - Prototype of class that are decorators applied to * @param methodName - Name of method that is being modified * @param descriptor - Descriptor of method that is being modified * @param args - Array of arguments passed to called method * @param request - Http request that you can modify * @param next - Used for calling next middleware with modified request */ run(_id, _target, _methodName, descriptor, _args, request, next) { if (isBlank(descriptor.responseType)) { return next(request); } let responseType; switch (descriptor.responseType) { case ResponseType.Json: case ResponseType.LocationHeaderAndJson: { responseType = 'json'; break; } case ResponseType.LocationHeader: case ResponseType.Text: { responseType = 'text'; break; } case ResponseType.Blob: case ResponseType.BlobAndFilename: { responseType = 'blob'; break; } case ResponseType.ArrayBuffer: { responseType = 'arraybuffer'; break; } } request = request.clone({ responseType: responseType }); return next(request); } } //# sourceMappingURL=produces.middleware.js.map