I am trying to perform two simple tasks. GET and POST with a free REST api i.e Jsonplaceholder using angular. I have a json db.json uploaded on my github account here which is very simple. It contains id and name of the book i.e. title
{
"myitems": [
{
"id": 1,
"title": "Bike Servicing System"
},
{
"id": 2,
"title": "Easy Base"
}
],
"profile": {
"name": "typicode"
}
}
I am using a free REST api service JSONPlaceholder. They call it a "Fake Online REST API for Testing and Prototyping". Anyways, my GET request works perfectly. Click here to see GET response. But why I am unable to put some further data to that json using POST. Please see if there is something wrong with my code.
post(opost: Posts): Observable<any> {
return this.httpclient.post("https://my-json-server.typicode.com/tmtanzeel/test-json-server/myitems", opost);
}
Where opost is an object of type Posts which is a class.
export class Posts {
id: number;
title: string;
}
I am not getting any error. Here I have put the entire angular project on github. And I was following this youtube tutorial. Please help me.
var opost = new Posts(); opost.id=3; opost.title='Dove Tail'; this._freeApiService.post(opost) .subscribe ( data=> { this.objposts = data; } );