Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Example of constructing responses in HTTP method interceptors + typings problem #243

Open

Description

@arturhun

Please provide a simple example of constructing a valid response in a method interceptor.

The ticket #44 refers to something that apparently has been moved, and the example in the README is very general, succinct and I find it not helpful at all.

Activity

  1. arturhun commented on Aug 14, 2019

    @arturhun
    Author

    By looking into interfaces.d.ts I managed to come up with something like:

    delete(reqInfo: RequestInfo) {
      reqInfo.utils.createResponse$(() => {
        return of({
          collection: collection.filter(item => !deleteSet.has(item.id)),
        });
      });
    }
    

    Functionally, this seems to work, however:

    • I assume one would also need to clone the reqInfo parameter to get all the headers, and other props
    • TS complains about the .utils type which allegedly doesn't exist on type RequestInfo, it doesn't exist on type string.

    We have type RequestInfo = Request | string;

    but (reqInfo as Request).utils. still leaves the squiggles underneath utils.

    The above shows that the docs leave much of guesswork for a developer and it could be avoided by provided a decent example.

  2. vishal423 commented on Aug 14, 2019

    @vishal423
    Contributor

    did you check under this directory for examples? https://github.com/angular/in-memory-web-api/tree/master/src/app

  3. changed the title [-]Example of constructing responses in HTTP method interceptors[/-] [+]Example of constructing responses in HTTP method interceptors + typings problem[/+] on Aug 14, 2019
  4. arturhun commented on Aug 14, 2019

    @arturhun
    Author

    OK, the typing problem came from that I didn't have an explicit import from the library and so TypeScript used RequestInfo from lib.dom.d.ts

  5. arturhun commented on Aug 14, 2019

    @arturhun
    Author

    @vishal423 Yes I did. and the code that I used based on that

    return of({
        items: collection.filter(item => !deleteSet.has(item.id)),  // my collection is `items`
    });
    

    didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions