2

I'm trying to make a get request to a certain URL but it seems to be replaced to another one,this resulting in making a get request to an non-existant URL.

Here is my code

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';


@Injectable()
export class ApitestProvider {
  tests;
  apiUrl = "http//:localhost:8000/api";
  testAdded;
  testGotten;
  testDeleted;
  constructor(public http: HttpClient) {

    console.log('Hello ApitestProvider Provider');
  }

  getTests() {
    this.http.get(this.apiUrl + "/tests").subscribe(data => {
      console.log(data);
      this.testGotten = data;
    }), err => {
      console.log(err);
    }

  }

but it ends up making a request for the following URL

url: "http://localhost:8100/http//:localhost:8000/api/tests"

thanks in advance.

2
  • Are you using an interceptor? Commented Dec 3, 2018 at 22:13
  • You can check your base url in your index.html file. Commented Dec 3, 2018 at 22:28

1 Answer 1

4

You have incorrectly typed your API URL.

instead of this: apiUrl = 'http//:localhost:8000/api';

it should be this: apiUrl= 'http://localhost:8000/api';

Stackblitz

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.