Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda