L
L
lexa324saa2020-08-12 20:09:13
JavaScript
lexa324saa, 2020-08-12 20:09:13

GET request in Postman gives status 200, but through the local server 304, how to fix it?

There are 2 TS files
categories-page.component.ts

import {Component, OnInit} from '@angular/core';
import {CategoriesService} from "../shared/servicis/categories.service";
import {Category} from "../shared/interfaces";

@Component({
  selector: 'app-categories-page',
  templateUrl: './categories-page.component.html',
  styleUrls: ['./categories-page.component.css']
})
export class CategoriesPageComponent implements OnInit {
  loading = false
  categor: Category[] = []

  constructor(private categoriesService: CategoriesService) {
  }

  ngOnInit() {
    this.loading = true
    this.categoriesService.fetch().subscribe(categories => {
      this.loading = false
      this.categor = categories
      console.log('Categories', categories)
    })
  }

}

categories.service.ts
import {Injectable} from '@angular/core'
import {HttpClient} from '@angular/common/http'
import {Category} from '../interfaces'
import {Observable} from 'rxjs'

@Injectable({
  providedIn: 'root'
})
export class CategoriesService {
  constructor(private http: HttpClient) {
  }

  fetch(): Observable<Category[]> {
    return this.http.get<Category[]>('/api/category')
  }
}

When a get request through Postman gives an array of categories, and through the server it gives an empty array

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question