Skip to content

Instantly share code, notes, and snippets.

@PyroGenesis
Last active May 19, 2019 11:12
Show Gist options
  • Save PyroGenesis/4a34c8ecc7fb3bc7cc2779ee93c317f1 to your computer and use it in GitHub Desktop.
Save PyroGenesis/4a34c8ecc7fb3bc7cc2779ee93c317f1 to your computer and use it in GitHub Desktop.
Angular request with Body (FormData and JSON)
POST_with_FormData(fileblob): Observable<any> {
const URL = 'YOUR_URL_HERE';
const data = new FormData();
data.append('product_Id', '123');
data.append('file', fileblob);
return this.httpClient.post<any>(URL, data); // returns an Observable
}
POST_with_JSON(): Observable<any> {
const URL = 'YOUR_URL_HERE';
const data = {
"testobj": {
"testnum": 5,
"teststr": "hello"
},
"testarr": [1, 2, 3]
}
return this.httpClient.post<any>(URL, JSON.stringify(data)); // returns an Observable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment