Call a WebAPI in ASP.Net Core MVC

Viewed 67

I have programmed a backend system in which I can manage data and then output it to an API. I did this because I want to convert a large project to a different language + framework, but I still want to integrate this backend system into the current version first, because it is much better than the old way. I have been looking for days how it works but I haven't really come to a result, I hope someone can help me.

example: I have a separate page for each member with some data from a biography etc. and I can have this displayed in the WebAPI under: "https://sub.domain.de/items/member" then all members and associated data is output. Now I want that I to: "https://www.domain.de/member/[John_Doe]" (John_Doe is of course an example value for every other member) can output certain data. the pages should of course still be generated dynamically.

ps: if it is necessary I can also enter "https://sub.domain.de/items/member/[John_Doe]" to only get the data from a specific member.

the json basically looks like this:

{
  "data": [
    {
      "name": "John_Doe",
      "status": "published",
      "user_created": "052a2c25-b063-4a82-90cb-110d7f809cae",
      "date_created": "2021-06-29T08:30:06+02:00",
      "title": "Doc John Doe",
      "Characteristics": "- **Lorem **: ipsum dolor sit amet\n- **Birthdate**: 1965",
      "bio": "- **Lorem ipsum**:\nLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
      "member": true,
      "section1": false,
      "section2": false,
      "portrait": null
    },
    {
      "name": "Jane",
      "status": "published",
      "sort": null,
      "user_created": "052a2c25-b063-4a82-90cb-110d7f809cae",
      "date_created": "2021-06-29T08:29:31+02:00",
      "title": "Jane",
      "Characteristics": "",
      "bio": "Bio unbekannt.",
      "member": true,
      "section1": false,
      "section2": true,
      "potrait": "30d17fe3-bcf7-4aa2-9759-49f3e257eb0f"
    }
  ]
}

and the bio and the characteristics are written in markdown.

I hope I was able to explain what I mean and someone can help me.

edit:

ps: my main problem is that i don't know how to get data from an api, and of course i not only have the area with the members, i still have a lot of articles and more but it works with the same logic.

1 Answers

I guess this totally depending in the routing. you can construct your api that returned the data with this url :"https://sub.domain.de/items/member/[John_Doe]" like so

[Route("items/member")]
[ApiController]
public class UserController : ControllerBase
{
    [HttpGet("{username}")]
    public IActionResult GetUserData(string username) {
    // your logic 
    } 
}
Related