0

My org returns the same object for any api.

This is a wrapper around the actual normal response you would expect from a restful api e.g. api/products returns MyOrgResponse object which might look like

{true, products[], notifications[] } 

and api/products/123 returns

{true, product123, notifications[] } 

This breaks the angular-in-memory-web-api as it expects a restful collection to access eg.

{products} or {product123}

I can extend the service and intercept the get(reqInfo: RequestInfo) {} method. Here I can repoint to the collection its looking for (if my api/products/123 was invoked for example). I then reconstruct the body to return a MyOrgObject.

The first bit works but any ideas on how I rebuild the body/response object as my subscription is blowing up saying

"TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable" ... 

I am doing this to reconstruct

 body:  {"operationSucceeded": true, "data": product, "notifications": []}

thanks

2
  • Add a method responseInterceptor(res: ResponseOptions, ri: RequestInfo): ResponseOptions {} in api-mock-service, do your restructuring here Commented Nov 2, 2018 at 10:51
  • I am sorry, I don't fully understand your question. api/products/123 is a url for in-memory right? What is returning this type of data: {true, product123, notifications[] } Commented Nov 2, 2018 at 10:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.