dotnet-fake-json-server
dotnet-fake-json-server copied to clipboard
Option to create a new Object
Is there an option to create a new object? Thanks!
Hi! Yes, you can post any data you, with any name (example has abcd) and it will be stored to JSON-file and can be fetched with the name you defined.
# Add new data
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{ "value": "1", "description": "hello", "random": "data" }' http://localhost:57602/api/abcd/
# Fetch created data
curl http://localhost:57602/api/abcd/0
If you have any other questions, just let me know :+1:
Hi, in this case, this will create an array inside the object abcd, I what I mean is to create for example:
"abcd": {
"value": "1",
"description": "hello",
"random": "data",
"id": 0
}
Sorry, misunderstood the question.
Change Api.UpsertOnPut to true from config:
https://github.com/ttu/dotnet-fake-json-server/blob/1068151e2912cff5a26fb7f7711f587ecdde5131/FakeServer/appsettings.json#L35
Replace/Add new object with PUT:
# Add new data
curl -H "Accept: application/json" -H "Content-type: application/json" -X PUT -d '{ "value": "1", "description": "hello", "random": "data" }' http://localhost:57602/api/abcd/
# Fetch created data
curl http://localhost:57602/api/abcd
Apparently there is nothing about objects it in the docs, besides the route list 🤔
PUT /api/{object}
PATCH /api/{object}
DELETE /api/{object}
Thanks for the question. I wouldn't have noticed this without it!
Awesome! Thanks a lot!!!