1

I am creating Cars store in Asp.Net for my school. I built an Api Method:

    [HttpGet("api/brands/{brandName}/models")]
    public IActionResult Get(string brandName)
    {

        {
            var model = _context.getBrandByName(brandName);
                return Ok(model.Models.ToList());

        }

    }

An it works when I am checking it with Postman.

Now I would like User to choose brandName from selection list in the website and show him avaliable models. In other words I dont know how to use this Api to get Data displayed.

Any help will be strongly appreciated

2 Answers 2

1

RESTful Web services are one way of providing interoperability between computer systems on the Internet. REST-compliant Web services allow requesting systems to access and manipulate textual representations of Web resources using a uniform and predefined set of stateless operations.

from Wikipedia.

This means, the REST API's only concern is to provide the data to work in a uniform and predefined set of operations, where those operations take the HTTP Verb that was used in consideration.

in your example, your GET route, should only be api/brands/{brandName}

the default in rest api, http verbs say:

GET - getting one element or a list
POST - creating
PUT - updating
DELETE - removing

in your application, the best approach would be something like:

GET /api/brands               will get ALL existing brands
GET /api/brands/<brand_name>  will get just one brand
POST /api/brands              will create a new brand
PUT /api/brands               will edit an existing brand
DELETE /api/brands            will delete an existing brand

from your question:

Now I would like User to choose brandName from selection list on the website

the website would then request a GET to the route /api/brands to get the list of all of the brands.

This is the REST API part, it concerns ONLY in providing the right data to the system that request it.

if you want to create a website in order to CONSUME this data, you can easily create a new web project in your solution and request the data that the API provides, making the Website completely "blind" from where the data comes from, as it only asks for the data itself.

Making the whole system much easier for updated and maintainability.

Sign up to request clarification or add additional context in comments.

Comments

1

In other words I dont know how to use this Api to get Data displayed.

The main purpose of REST API is to expose data not to display it by using any kind of UI framework.

If you think you need to manage the full stack of your application end-to-end. I mean from User interface to your database then you must think at implementing the V of the MVC pattern bu return a view and not just a data. ASP.Net Core can help you with that. Follow this tutorial, it explains a lot about this pattern in ASP.Net Core MVC.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.