-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
If I create a minimal app using the REST CRUD example, which uses the CrudRestComponent, then PUTting a new Todo returns a 404, when I believe it should create the resource:
https://tools.ietf.org/html/rfc7231#section-4.3.4
The PUT method requests that the state of the target resource be
created or replaced with the state defined by the representation
enclosed in the request message payload.
(emphasis mine)
Steps to reproduce
- Create an example rest-crud app:
$ npm install -g @loopback/cli
$ lb4 example rest-crud
$ cd loopback4-example-rest-crud
$ npm start
- Send the following HTTP request:
PUT http://localhost:3000/todos/101
{
"id": 101,
"title": "Todo 101",
"desc": "Test CRUD PUT",
"isComplete": false
}
Current Behavior
- Response is a 404:
{
"error": {
"statusCode": 404,
"name": "Error",
"message": "Entity not found: Todo with id 101",
"code": "ENTITY_NOT_FOUND"
}
}
- Todo is not created.
Expected Behavior
- Response is a 201.
- Todo is created.
Additional information
$ node -e 'console.log(process.platform, process.arch, process.versions.node)'
linux x64 14.0.0
$ npm ls --prod --depth 0 | grep loopback
@loopback/example-rest-crud@1.7.1 /var/data/tmp/loopback4-example-rest-crud
├── @loopback/boot@3.1.0
├── @loopback/core@2.12.0
├── @loopback/repository@3.2.0
├── @loopback/rest@9.0.0
├── @loopback/rest-crud@0.8.17
├── @loopback/rest-explorer@3.0.3
├── loopback-connector-rest@3.7.0
Related Issues
Whilst this bug is specifically about the CrudRestComponent, the following all mention upsert or createOrReplace, which seems to be the core of the issue.
2550 - Add upsert functionality to DefaultCrudRepository
1920 - Feature parity with LoopBack 3.x
2273 - How to replaceById/replaceOrCreate with HasManyRepository
2550 in particular seems to have been accepted as a valid case, but then was eventually closed as nothing happened on it for 6 months.