angularangular-in-memory-web-api

id should be optional in angular-in-memory-web-api


According to read me for angular-in-memory-web api 'The in-memory web api library currently assumes that every collection has a primary key called id' Is there any option to have no id? as I would like to generate following response

{
    success: boolean;
    token: string;
}

Is it also possible to generate a string own its on, as my application returns a string when a post has been made.


Solution

  • I'm finding it's worse than this.

    Not only must you have a Primary Key value in each of your tables called id but it must be a string, not a number. (Huh ?!!)

    If you don't do this, when when you try to call the PUT endpoint, the Angular code will throw an error on this line:

    BackendService.prototype.put = function (_a) {
        . . . 
        if (id && id !== item.id) {
            return this.createErrorResponseOptions(url, STATUS.BAD_REQUEST, "Request for '" + collectionName + "' id does not match item.id");
        }
    

    If your table contains a numeric id value, then this line will end comparing something like "100" with 100, and will throw an error.

    (Sigh.)