localhost/ci-abc/api/get_userid?username=yousuf
This is the API that works in postman and returns the userid
However I am a beginner developer so I am confused how do I pass a parameter in angular http service method to codeigniter's API. APIs with no parameter required works fine but I am not able to find a way to pass the parameter of username in order to get its id.
Ive searched a bit and was able to find URLSearchParams() as a solution but it didn't work, here is what i did.
getUserid()
{
let myParams = new URLSearchParams();
myParams.append('username', 'yousuf');
console.log(myParams);
return this.http.get('http://localhost/ci-abc/api/get_userid', {params : myParams})
.map(res=>res.json());
}
and the API in codeigniter is
function get_userid_get()
{
$username = $this->get('username');
if (!$username) {
$this->response("No username specified", 400);
exit;
}
$result = $this->user_model->get_userid($username);
if ($result) {
$this->response($result, 200);
exit;
} else {
$this->response("Invalid username", 404);
exit;
}}
it has been few hours im trying different ways but no luck so ill appreciate the help
Mozilla Firefox comes up with this error in the console.
ERROR {…} _body: "\"No username specified\"" headers: Object { _headers: Map, _normalizedNames: Map } ok: false status: 400 statusText: "Bad Request" type: 2 url: "http://localhost/ci-abc/api/get_userid" proto: Object { constructor: Response(), toString: Response.prototype.toString() }