0

I have a simple endpoint in flask like the below.

@ns.route ('/cars/<string:make>/<string:model>')

class CarClass (Resource):
    def get (self, make):
        year=request.args.get ('year', type=int)
        website=request.args.get ('website', type=path)
        # do something

Important points to consider are as follows

  1. URL Parameters introduced to illustrate that these are mandatory parameters and the order matters
  2. Query Parameters introduced to illustrate that there are optional parameters (with no relevant ordering)
  3. Website Parameter introduced to illustrate complications with forward slashes and the need to encode paths

When making the API call I think I can pass the query parameters through the data portion, but I am forced to manual create the URL and make an ajax call, like so

url = `https://example.com/cars/${make}/${model}`

try
{
    data = await $.ajax({
    type: 'GET',
    url: url,
    data: JSON.stringify({
        year: year,
        website: website
    }),
    datatype: 'json',
    contentType: 'application/json; charset=utf-8'
    });
}

Is there a builtin Ajax way of passing URL parameters or must I resort to such string manipulation of the URL?

Background: I find the majority of answers to my question simply tell the coder to put the parameters into an object and pass it to data, but when I do this I get a 404 error because the API is looking for /cars/<make>/<model> not /cars

0 Answers0