C
C#2y ago
Lisa

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
Angius
Angius2y ago
You mean, you need to create a GetBuildingsFromCompany endpoint and verify that it works with Swagger? Because Swagger is not an API
k.n.w
k.n.w2y ago
I 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.
DoctorShammy
DoctorShammy2y ago
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 🙂
cap5lut
cap5lut2y ago
whats the url of the request u are receiving the 404 for?
Angius
Angius2y ago
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 work
cap5lut
cap5lut2y ago
if 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 mentioned
DoctorShammy
DoctorShammy2y ago
this 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();
DoctorShammy
DoctorShammy2y ago
this is the end point Im trying to reach
No description
DoctorShammy
DoctorShammy2y ago
please tell me if you need My Controller, Repo, Model or any other code snippet
cap5lut
cap5lut2y ago
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?
DoctorShammy
DoctorShammy2y ago
yes the endpoint works, I do have a Building controller but it fetches data from another Api https://codeshare.io/dwzgDD Building Controller
cap5lut
cap5lut2y ago
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 controller
DoctorShammy
DoctorShammy2y ago
hm maybe I should make a new buildingcontroller for the new api?
cap5lut
cap5lut2y ago
maybe u should tell/show us first how the routing is set up
DoctorShammy
DoctorShammy2y ago
im really noob, this is why I don't really understand what you need
cap5lut
cap5lut2y ago
that swagger screenshot + default route mapping would mean u have a BuildingController with a GetBuildingsFromCompany() method somewhere
DoctorShammy
DoctorShammy2y ago
I 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
cap5lut
cap5lut2y ago
can u show ur complete Program.cs?
cap5lut
cap5lut2y ago
thats the rouing part and is the default mvc routing
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
DoctorShammy
DoctorShammy2y ago
ye
cap5lut
cap5lut2y ago
whats the url of of the swagger site where u got that screenshot from?
cap5lut
cap5lut2y ago
then it seems like u havent configured the request in postman correctly
DoctorShammy
DoctorShammy2y ago
ok what did I do wrong?
cap5lut
cap5lut2y ago
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
DoctorShammy
DoctorShammy2y ago
all i can see in the console in devtools is 404
cap5lut
cap5lut2y ago
it also might be that the controller's endpoint is returning 404 completely functional. basically its now back to ⤴️
DoctorShammy
DoctorShammy2y ago
🥲

Did you find this page helpful?