Reputation: 6326
I have a basic API call that takes in two id's and adds them to a favorites matrix of users to profiles. I've set the call up in C# MVC like so:
[Route("api/discovery/addToFavourite/{profileid}/{userid}")]
public void AddToFav(int profileid, int userid)
{
var Favourite = new Favourite();
Favourite.ProfileId = profileid;
Favourite.UserId = userid;
WildWalkDb.Favourites.Add(Favourite);
WildWalkDb.SaveChanges();
}
And then from Angular 2 and TypeScript I have:
addToFav(profileid) {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: headers });
return this.http.post(this.url + '/api/discovery/favourite/' + profileid + '/' + 1)
.toPromise()
.then(response => <string>response.statusText)
.catch(this.handleError);
}
I just need to run that url with the parameters without passing any Json or anything over, but this fails, presumably because it's missing additional parameters on the http.post call. So from all this I'm guessing this isn't the best way to do this and maybe I'm majorly missing the point of how post calls work? What's the best way for me to just make that api call?
Upvotes: 0
Views: 232
Reputation: 803
If the parameters are not required, make them optional then at runtime fill/provide them, otherwise provide them at call point.
--(Edit) Provide empty values at call point.
Upvotes: 1