Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
What do i need to do after making an api call using refit

I'm learning a little more about Restful in C# .NET but I'm having some problems when I call an API. I had done a similar project before and it worked, but using the same template for this specific API is no longer working.

The idea is to consult an API (https://pokeapi.co) and check if the typed pokemon exists, maybe print its abilities or something along those lines, but when I make my call, the console returns "An error occurred deserializing the response. "

My code is quite simple, I split it into 3 parts:

Pokeresponse.cs

namespace Pokedex
{
    public class PokeResponse
    {
        [JsonProperty("pokemon")]
        public string Pokemon { get; set; }
        [JsonProperty("id")]
        public string Id { get; set; }        
    }
}

Program.cs

namespace Pokedex
{
    class Program
    {
        static async Task  Main(string[] args)
        {
            try
            {
                var pokemonClient = RestService.For<IPokeApiService>("https://pokeapi.co/api/v2");
                Console.WriteLine("Informe o pokemon");
                string informedPokemon = Console.ReadLine().ToString();

                Console.WriteLine($"Consultando informacoes do pokemon {informedPokemon}");
                var poke =await pokemonClient.GetAddressAsync(informedPokemon);
                Console.WriteLine($"\nAbilities:{poke.Id} ");
                Console.ReadKey();
            }
            catch(Exception e) 
            {
                Console.WriteLine("An Error occurred when searching for the pokemon"+ e.Message);
            }

        }
    }
}

IPokeApiService

namespace Pokedex
{
    public interface IPokeApiService
    {
        [Refit.Get("/pokemon/{pokemon}")]
        Task<PokeResponse> GetAddressAsync(string pokemon);
    }
}

could anyone give any tips on how to proceed? I tried to debug it but didn't get much progress.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you take a look at the JSON response from docs you can see that there is no Pokemon field(so rename it to Name), also Id should be int(that was the real cause of exception)

Result:

public class PokeResponse
{
    public string Name { get; set; }

    public int Id { get; set; }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!