local function get_method( request)
local method, path, query_fragment = request: match( "^(.+) ([^%?]+)(%??.*) .+$" )
if method and path then
return method .. "_" .. path
else
return nil
end
end
local function get_method_updated( request)
local method, path, query_fragment = request: match( "^(.+) ([^%?]+)(%??.*) .+$" )
if method and path then
if path: match( '^/[^/]+/[^/]+/[%w_]+' ) ~= nil then
return method .. " " .. path
else
return method .. "_" .. path
end
else
return nil
end
end
-- You have
print ( get_method( "GET /v1/merchants something" ) )
print ( get_method( "GET /v1/content/merchants/foo or" ) )
print ( get_method( "GET /v1/content/merchants/bar some" ) )
-- Do you want?
print ( get_method_updated( "GET /v1/merchants something" ) )
print ( get_method_updated( "GET /v1/content/merchants/foo or" ) )
print ( get_method_updated( "GET /v1/content/merchants/bar some" ) )
bG9jYWwgZnVuY3Rpb24gZ2V0X21ldGhvZChyZXF1ZXN0KQogIGxvY2FsIG1ldGhvZCwgcGF0aCwgcXVlcnlfZnJhZ21lbnQgPSByZXF1ZXN0Om1hdGNoKCJeKC4rKSAoW14lP10rKSglPz8uKikgLiskIikKICBpZiBtZXRob2QgYW5kIHBhdGggdGhlbgogICAgcmV0dXJuIG1ldGhvZCAuLiAiXyIgLi4gcGF0aAogIGVsc2UKICAgIHJldHVybiBuaWwKICBlbmQKZW5kCmxvY2FsIGZ1bmN0aW9uIGdldF9tZXRob2RfdXBkYXRlZChyZXF1ZXN0KQogIGxvY2FsIG1ldGhvZCwgcGF0aCwgcXVlcnlfZnJhZ21lbnQgPSByZXF1ZXN0Om1hdGNoKCJeKC4rKSAoW14lP10rKSglPz8uKikgLiskIikKICBpZiBtZXRob2QgYW5kIHBhdGggdGhlbgogIAlpZiBwYXRoOm1hdGNoKCdeL1teL10rL1teL10rL1sld19dKycpIH49IG5pbCB0aGVuCiAgCQlyZXR1cm4gbWV0aG9kIC4uICIgIiAuLiBwYXRoCiAgCWVsc2UKICAgIAlyZXR1cm4gbWV0aG9kIC4uICJfIiAuLiBwYXRoCiAgICBlbmQJCiAgZWxzZQogICAgcmV0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