elliotgao2/toapi

Modify routing argument

alvinwoon opened this issue · 2 comments

class Meta:
source = NONE
route = {'/search/:id': '/search/:id'}

Right now ID for host url passes directly into source url. Is there a way we can modify ID before passing them on?

For example, I need to map the query 127.0.0.1:5000/search/1 to bing.com/search/100

So I am going to have to multiply :id with 100 before passing it as argument. Not sure if that makes sense.

Hi @alvinwoon :

There is a solution here:

    @api.server.app.route('/<int:get_id>')
    def search_id(get_id):
        res = api.parse('/' + str(100 * get_id))
        return api.server.app.response_class(
            response=res,
            status=200,
            mimetype='application/json'
        )

But I still want to say, i'm sorry I can't understand why there's such a demand , is not it better to use 127.0.0.1:5000/search/100 directly?

Thanks again for the example. Sometimes your internal data has a different ID structures to the 3rd party pages you are trying to crawl. Being able to map them is very useful :)