angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 232 forks source link

How do I access request body in RequestInfo? #188

Closed hjchin closed 6 years ago

hjchin commented 6 years ago

Hi,

I'm trying to retrieve the request body from RequestInfo and put some logic in the interception to mimic the backend logic.

When I dump the RequestInfo from chrome dev tool, I can see it is in RequestInfo.req.body. Req is a type of HttpRequest. However, the interfaces.ts where RequestInfo interface is defined, states req is a type of RequestCore. RequestCore has total different definition than HttpRequest.

How do I retrieve request body in RequestInfo? Thanks.

export interface RequestCore {
  url: string; // request URL
  urlWithParams?: string; // request URL with query parameters added by `HttpParams`
}

/**
* Interface for object w/ info about the current request url
* extracted from an Http Request.
* Also holds utility methods and configuration data from this service
*/
export interface RequestInfo {
  req: RequestCore; // concrete type depends upon the Http library
  apiBase: string;
  collectionName: string;
  collection: any;
  headers: HeadersCore;
  method: string;
  id: any;
  query: Map<string, string[]>;
  resourceUrl: string;
  url: string; // request URL
  utils: RequestInfoUtilities;
}
hjchin commented 6 years ago

for now, I add an interface

export interface HttpRequest{
  body: string;
}

and assign req to this type just to get it works,

hjchin commented 6 years ago

Only now I read this comment.

/**
* Interface for object w/ info about the current request url
* extracted from an Http Request.
* Also holds utility methods and configuration data from this service
*/

It closes to what I thought. I just add body to the RequestCore then. Thanks

wardbell commented 6 years ago

Looks like you're ok. Closing

ghost commented 5 years ago

Why is this closed?