# A way to build a URL route

**URL:** <https://discourse.nameko.io/t/a-way-to-build-a-url-route/299>\
**Category:** Github Issues\
**Created:** [August 13, 2018, 9:33am UTC](https://discourse.nameko.io/t/a-way-to-build-a-url-route/299 "2018-08-13T09:33:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [August 13, 2018, 9:33am UTC](https://discourse.nameko.io/t/a-way-to-build-a-url-route/299/1 "2018-08-13T09:33:15Z")

</div>

_From @asyncee on Wed May 02 2018 07:26:29 GMT+0000 (UTC)_  
  
Hello!

I have a service with eight http endpoints and i need to build urls for it with multiple different parameters. Are there any way to implement something like `url_for` in flask:

Example:

```auto
class Service:
    @http('GET', '/url-one/<token>')
    def handle_url_one(self, request, token):
        pass
    
    @rpc
    def get_url_one(self):
        return '/url-one/' + token # This is not DRY and error-prone approach
        # Wanted: return self.url_for(self.handle_url_one, token)

```

Thanks!  
  
_Copied from original issue: [https://github.com/nameko/nameko/issues/539](https://github.com/nameko/nameko/issues/539)_

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [August 13, 2018, 9:33am UTC](https://discourse.nameko.io/t/a-way-to-build-a-url-route/299/2 "2018-08-13T09:33:17Z")

</div>

_From @mattbennett on Wed May 02 2018 12:38:33 GMT+0000 (UTC)_  
  
Nameko HTTP is built on Werkzeug, which is the WSGI library that underpins Flask. `url_for` is one of the conveniences that Flask adds, so it’s not available out of the box.

It’s not that hard to implement though. Nameko entrypoints attribute the service methods that they decorate, so you can inspect the service class to find them. This snippet should get you started:

```python
from nameko.extensions import ENTRYPOINT_EXTENSIONS_ATTR
from nameko.web.handlers import http, HttpRequestHandler
from nameko.rpc import rpc

class Service:
    name = "serv"

    @http('GET', '/url-one/<token>')
    def handle_url_one(self, request, token):
        pass

    @rpc
    def get_url_one(self, token):

        entrypoints = getattr(self.handle_url_one, ENTRYPOINT_EXTENSIONS_ATTR)
        routes = [
            entrypoint.url for entrypoint in entrypoints
            if isinstance(entrypoint, HttpRequestHandler)
        ]
        return routes

```

Returns `['/url-one/<token>']`. The logic you need to substitute the arguments into the string must exist in werkzeug somewhere.
