Web Api request in asp.net core mvc project
Could you provide more context? eg. the controller, what requests you are making, ect.?
30 Replies
You mean, you need to create a
GetBuildingsFromCompany
endpoint and verify that it works with Swagger?
Because Swagger is not an APII don't know what you're trying to reach, but 404 stands for "not found", there can be no available end point, or not found the data.
Yes! I have a Company controller class, a Company Repo, CompanyView, Company Modal.
here is a codeshare link with the code: https://codeshare.io/qPkr1B
it's code from all the classes involved
I've checked and the endpoint matches the endpoing in the api.
Please look at my answer above 🙂
whats the url of the request u are receiving the 404 for?
it's "https://datastorage-fake-myrspoven.azurewebsites.net/Building/GetBuildingsFromCompany",
tried it via postman
I don't see any
BuildingController
nor any GetBuildingsFromCompany
endpoint
Unless you have it all set up in Program.cs
with explicit routing or something, this route has no right to workif its the endpoint at line 35, then the url path should be either
/companies/someCompanyId
or /someCompanyId
unless routing is set up differently as ZZZZZ mentionedthis is the routing:
builder.Services.AddControllersWithViews();
builder.Services.AddHttpClient();
builder.Services.AddScoped<IBuildingRepository, BuildingRepository>();
builder.Services.AddScoped<ISignalRepository, SignalRepository>();
builder.Services.AddScoped<ICompanyRepository, CompanyRepository>();
builder.Services.AddScoped<ApiClient>();
builder.Services.AddScoped<CompanyApiHandler>();
builder.Services.AddControllersWithViews();
this is the end point Im trying to reach

please tell me if you need My Controller, Repo, Model or any other code snippet
the routing is done with the app, not with the builder, eg. something like
app.MapControllers();
or some other way of routing
if its the default way of rouing, u have shown us the wrong controller, there should be a BuildingController
more i cant say right now
does the endpoint work if u use swagger's try out functionality?yes the endpoint works, I do have a Building controller but it fetches data from another Api
https://codeshare.io/dwzgDD Building Controller
u should check the dev tools of ur browser and look what the request looks like there, seems like its different from what u r doing in postman
also u have shown now the
BuildingsController
not the BuildingController
(singular vs. plural), so either its not default route mapping and u should show us that mapping as well or this is again the wrong controllerhm maybe I should make a new buildingcontroller for the new api?
maybe u should tell/show us first how the routing is set up
im really noob, this is why I don't really understand what you need
that swagger screenshot + default route mapping would mean u have a
BuildingController
with a GetBuildingsFromCompany()
method somewhereI have a Building controller that I wrote for another Api, so I am guessing that it doesn't match the Building Controller for this API, I haven't written a BuildingController
can u show ur complete
Program.cs
?thats the rouing part and is the default mvc routing
ye
whats the url of of the swagger site where u got that screenshot from?
then it seems like u havent configured the request in postman correctly
ok what did I do wrong?
i can not say.
compare what u do in postman with what ur browser's network tab for the development tools (usually accessible via F12) shows, when u use the try out feature
all i can see in the console in devtools is 404
it also might be that the controller's endpoint is returning 404 completely functional.
basically its now back to ⤴️
🥲