0

i am trying to create dummy login from inmemory db angular without using any json file or live api for in memory service i am using users object

const users = [ 
      { id: 1, userName: 'abhijeet', password: 'abh@123'},
    ];

using http response

const url = `${environment.apiEndPoint}users?userName=^${user.userName}$&password=^${user.password}$`;
    this.http.get<UserDetails>(url).subscribe(resp => {
      let user = resp;

error is

{body: {…}, url: "/api/users?userName=^abhijeet$&password=^abh@123$", headers: HttpHeaders, status: 404, statusText: "Not Found"}
body:
error: "Collection 'undefined' not found"
__proto__: Object
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 404
statusText: "Not Found"
url: "/api/users?userName=^abhijeet$&password=^abh@123$"

if i remove @ from password field and use underscore instead i am getting correct response but @ is not working for any filed.

1
  • You can use escape character before @ like this \@ Commented Aug 7, 2020 at 6:12

1 Answer 1

0

You should not use those @ in get calls of http. It will expects in form of encoding.

Also, it seems like your api call is login, dont use ^ for making query for logins, it works for like condition. But for login, it should exactly match the values.

try following, it will works

const url = `${environment.apiEndPoint}users?userName=${user.userName}$&password=encodeURI(${user.password})$`;
    this.http.get<UserDetails>(url).subscribe(resp => {
      let user = resp;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.