-
Notifications
You must be signed in to change notification settings - Fork 0
Web API Controller
Derek Peacock edited this page Dec 21, 2022
·
1 revision
This is a standard way of providing online access to data on the web. This service class will have CRUD methods for:-
- GetAllAddresses()
- GetAddress(int id)
- PostAddress(Address address)
- PutAddress(int id, Address address)
- AddressExists(int id)
This class can be scaffolded or create from an empty API Controller. Iwas unable to get this working without removing the Async methods
namespace BlazorShoes.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AddressesController : ControllerBase
{
private readonly ApplicationDbContext _context;
public AddressesController(ApplicationDbContext context)
{
_context = context;
}
// GET: api/Addresses
[HttpGet]
public List<Address> GetAddresses()
{
return _context.Addresses.ToList();
}
}
}The Service must be registered in the program.cs class
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
// Add Services and API Controllers
builder.Services.AddScoped<BasketService>();
builder.Services.AddScoped<AddressService>();
builder.Services.AddScoped<AddressesController>();BNU CO550 Web Applications | Dr Derek Peacock | 2022 Semester 1
Recorded Videos
ASP.NET Core 8
Blazor
React
MS Fabric
Filtering Products
Partial Pages
Git & GitHub
2021 Project Demos
Blazor CRUD
Address Service
API Controller
AddressTable 1
AddressTable 2
Upsert Address
Logbooks
LogBook 1
LogBook 2
LogBook 3
LogBook 4
LogBook 5