2

I created this basic data service for todos:

import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Todo } from './todos.service';

export class TodosData implements InMemoryDbService {

createDb() {
    const todos: Todo[] = [
        {
            id: 1,
            title: 'TODO 1',
        }
    ];
    return { todos };
}

}

Here is how the service is consumed:

const apiUrl = 'api/todos/'

// CREATE
create(todo: Todo){return this.http.post<Todo>(apiUrl, {...todo, id: null})}

// UPDATE
update(todo: Todo){return this.http.put<Todo>(apiUrl + todo.id, todo)}

When subscribing on the create fn (POST), then the new Todo is returned.

But when subscribing on the update fn (PUT), then null is returned.

Is that a bug or a feature?

When refreshing the list (GET) then the updated Todo is there as expected.

Is there a way to let the PUT also return the updated TODO instead of null?

1 Answer 1

2

Found a solution here: Correct way to do a PUT or POST in angular-in-memory-web-api

PUT does not return by default.

But it can be enabled: HttpClientInMemoryWebApiModule.forRoot(TodosData, { put204: false }),

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.