Hello guys
I'am currently working in Xamarin and got stucked with basic operation. Iam trying to call my NetCore web API from Xamarin using Refit.
The main problem is - I guess - that i want to pass object in paramater of call. The second problem could be that object has a List of enums as property.
Models:
public class ArticleFilter
{
public List<ArticleType> Types { get; set; }
public int? CarBrandId { get; set; }
}
public enum ArticleType
{
News = 1,
SpecialOffer = 2,
Service = 3,
}
Refit Interface:
[Headers("Content-Type: application/json")]
public interface IArticleApi
{
[Get("/api/articles")]
[Headers("Content - Type: application / json")]
Task<List<Article>> GetAll(ArticleFilter filter);
[Get("/api/articles/{id}")]
Task<ArticleDetail> GetOne(int id);
}
Api controller:
[HttpGet]
public async Task<IActionResult> GetAll([FromUri] ArticleFilterDto filter)
{
var articles = await _articleSectionService.GetAll(filter);
if (articles == null)
{
return NotFound();
}
return Ok(articles);
}
Test calls from Xamarin view model:
var filter = new ArticleFilter()
{
Types = new List<ArticleType> { ArticleType.News }
};
var test = new List<Article>();
test = await response.GetAll(filter);
Actually this one falls in exception - 415 - Unsupported media type
I came across their GitHub documentation but still no progress. Could some Superman help me please?