def build_uri(orig_uriparts, kwargs):
    """
    Build the URI from the original uriparts and kwargs. Modifies kwargs.
    """
    uriparts = []
    for uripart in orig_uriparts:
        if uripart.startswith('_'):
            part = str(kwargs.pop(uripart, uripart))
        else:
            part = uripart
        uriparts.append(part)
    uri = '/'.join(uriparts)
    id = kwargs.pop('id', None)
    if id:
        uri += '/%s' % id
    return uri
