Hey there! I have implemented back-end for Ionic. Until then I tested my api using cURL from my Linux terminal. I used this command: curl --data "some=parameter&another=parameter&and=another&one=parameter" https://myserver/api/my/endpoint. So, how can I do that the same thing using Ionic?
Also, please apologize my english. Iām not native.
You should use a provider for this. You can read more info here: https://angular.io/tutorial/toh-pt4
This is a simple example of a http post for ionic:
import { Http, Response } from '@angular/http';
export class Api {
constructor(public http: Http) {}
post(apiUrl: string, data: any = {}) {
return this.http.post(apiUrl, JSON.stringify(data))
.map((response: Response) => {
return response.json();
});
}
}
ā¦and my server responded but with error. The problem is my params (some=parameter&another=parameter&and=another&one=parameter"). With one parameter it works ok, but with more than one, itās useless.
If you want to pass the params with this format you should use URLSearchParams as @rapropos
suggested.
An example for your case:
let params = new URLSearchParams()
params.append(āsomeā, parameter); ā¦ etc