❔ api doesn't return anything.

https://github.com/emt2dev/MandalorianAPI .net 6
using MandalorianAPI.Models;
using MandalorianAPI.Data.Enums;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace MandalorianAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class MandoController : ControllerBase
{
private readonly ILogger<MandoController> _logger;

public MandoController(ILogger<MandoController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetMando")]
public IActionResult Index()
//public async Task<IActionResult> Index()
{

var moldyCrow = new StarShip
{
Id = "MC1",
Type = "Mandalorian Dropship",
HyperDriverCapable = true,
Name = "The Moldy Crow",
Ability = Ability.Cloaking,
};

var BoKatanKryze = new Mando
{
Clan = "Kryze",
Name = "Bo-Katan",
Signet = "Night Owls",
HelmetType = "Slim",
ArmorColorPrimary = "Blue",
ArmorColorSecondary = "Teal",
ArmorSpandexColor = "Tan",
SkillSet = SkillSet.Pilot,
Weapon = Weapon.Blaster,
HomePlanet = "Mandalore",
StarShipId = "MC1",
StarShip = moldyCrow,
};

// var objReturning = JsonConvert.SerializeObject(BoKatanKryze);

return Ok(JsonConvert.SerializeObject(BoKatanKryze));
}
}
}
using MandalorianAPI.Models;
using MandalorianAPI.Data.Enums;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace MandalorianAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class MandoController : ControllerBase
{
private readonly ILogger<MandoController> _logger;

public MandoController(ILogger<MandoController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetMando")]
public IActionResult Index()
//public async Task<IActionResult> Index()
{

var moldyCrow = new StarShip
{
Id = "MC1",
Type = "Mandalorian Dropship",
HyperDriverCapable = true,
Name = "The Moldy Crow",
Ability = Ability.Cloaking,
};

var BoKatanKryze = new Mando
{
Clan = "Kryze",
Name = "Bo-Katan",
Signet = "Night Owls",
HelmetType = "Slim",
ArmorColorPrimary = "Blue",
ArmorColorSecondary = "Teal",
ArmorSpandexColor = "Tan",
SkillSet = SkillSet.Pilot,
Weapon = Weapon.Blaster,
HomePlanet = "Mandalore",
StarShipId = "MC1",
StarShip = moldyCrow,
};

// var objReturning = JsonConvert.SerializeObject(BoKatanKryze);

return Ok(JsonConvert.SerializeObject(BoKatanKryze));
}
}
}
This is installed via pkg mgr. Here is my builder
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(options =>
{

}); // Allows to return JSON
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(options =>
{

}); // Allows to return JSON
GitHub
GitHub - emt2dev/MandalorianAPI: building a rest api for mandalorians.
building a rest api for mandalorians. Contribute to emt2dev/MandalorianAPI development by creating an account on GitHub.
5 Replies
friedice
friedice2y ago
so you're getting a 200 but no response data?
Omnissiah
Omnissiah2y ago
well you could use public async Task<IActionResult<Mando>> Index() also don't use JsonConvert.SerializeObject, just return BoKatanKryze
Candyroll93
Candyroll93OP2y ago
yes that is correct. keep in mind this is my first api that i've thrown together without any help. tyvm. may i ask why the weahther controller sends an ienum but forsome reason im choosing to send an iactionresult like mvc?
Angius
Angius2y ago
Task<IActionResult<Whatever>> is more explicit than Task<Whatever>, but for the most part the latter will be converted into the former anyway The IActionResult part, though, lets you return... action results. Like Ok() or NotFound() Besides just returning the desired object (also, uninstall Newtonsoft, with System.Text.Json being a thing now, it's basically useless)
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server