I have created a Api with React (Hooks)
and i geet getting this error:
my Api:
C#
{[Route("api")]
[ApiController]
public class HomeController : ControllerBase
{
private readonly DbProductContext _context;
public HomeController(DbProductContext context)
{
_context = context;
}
[HttpGet("{id}")]
public async GetSingleData(int id)
{
var find = await _context.products.FindAsync(id);
if (find == null)return NotFound();
return find;
}
}}and my React/Javascripts fetch part:
JavaScript
console.log("test4");
fetch('api/2').then(res => res.json()).then(data =>
console.log(data)).catch(error =>
console.error('Unable to get items.', error));
}I have even hard-coded the (existing) id that of the product that i want to get data from
After the Test4 console message i get the : SyntaxError: Unexpected token < in JSON at position 0
what am i doing wrong?! please help me out.

Sachin SinghRank #66 · 26.2K reputationPosted Jun 24, 2021, 4:26 PM EDT
osyris zosarRank #6,574 · 262 reputationPosted Jun 24, 2021, 4:49 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jun 25, 2021, 4:32 AM EDT