I have a route with POST Method 'http://localhost:5000/cities' where I can send json data like
[{ "id:" 1, "name": "LA", "country": "USA", "value": 10000 }]
In Angular, there is a service (cities.service.ts) responsible for posting this data
export class CitiesService {
constructor() { }
send_cities(data): Observable<Result> {
return this.post(this.Url(), data);
}
}
There is also a component (cities.component.ts) that utilizes this service
let city_code = this.form.value;
swal({
title: '',
text: '',
type: 'info',
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true
}, function () {
self.citiesService.send_cities(city_code, self._city.id, self._city.name, self._city.country, self._city.value).subscribe(
response => {
swal({
title: "",
text: "",
type: "success",
timer: 1500,
showConfirmButton: false
});
What is the best way to post data in json format to the api as demonstrated in the example?