I am learning to make a web api with .NET core and I followed this documentation.
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.1
I have made a new fresh project to start with and this is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace FortniteAPI.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public string Get()
{
return "https://api.fortnitetracker.com/v1/profile/{platform}/{nickname}";
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
}
}
I am using data from this website for my web API https://www.fortnitetracker.com/
The API link requires two parameters and that is platform and nickname. I used my own information but when I start the app I don't see the data.
I also have a header key to use it and this is shown in the documentation.
To use the API key you need to pass it along as a header with your requests.
I don't really understand this sentence.
Also I am programming in Ionic 3 and I used this api link with the HTTP get but it didn't work because of CORS. That's why I use a .NET core application to talk with the client.
Can someone point me in the right direction?
UPDATE
[HttpGet]
public string Get()
{
HttpClient http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("APIKEY", header);
var data = http.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
return data;
}