Registering endpoints and HTTP method for exemption of authentication I have a set of API endpoints where the URL is not standardized, so I could either get "api/auth" or "api/auth/" (may or may not end with "/"). I'm 'registering' the endpoint, plus the HTTP Method that comes in, so I can exclude certain endpoints from having to authenticate.

I've written this piece of code, which has a lot of repetition. Any thoughts? 

Private _ExemptEndpoints As New List(Of Tuple(Of String, Method))
Public Sub RegisterAuthExemptEndpoint(endpoint As String, method As Method) Implements IRestAuthenticator.RegisterAuthExemptEndpoint

    Dim endpoints As New List(Of Tuple(Of String, Method))
    Dim allMethods As Boolean = False
    If method = Nothing Then allMethods = True

    Dim ep1
    Dim ep2

    If Not endpoint.EndsWith("/") Then
        ep1 = endpoint
        ep2 = endpoint + "/"
    Else
        ep1 = endpoint.Remove(endpoint.Length - 1, 1)
        ep2 = endpoint
    End If

    If allMethods Then
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.GET))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.POST))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.PUT))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.DELETE))

        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.GET))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.POST))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.PUT))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.DELETE))
    Else
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method))
        _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method))
    End If

End Sub
Basically what you are asking is what can we do about this


    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.GET))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.POST))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.PUT))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method.DELETE))

    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.GET))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.POST))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.PUT))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method.DELETE))



and the contents of the else block as well.

I would create a method that takes the Endpoints ep1 and ep2 as parameters

something like 

Public Sub MethodAddingEndpointsToExemptedList(endpoint As String)
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(endpoint, method.GET))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(endpoint, method.POST))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(endpoint, method.PUT))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(endpoint, method.DELETE))
End Sub


and then you can just call this method inside the if block like this

If allMethods Then
    MethodAddingEndpointsToExemptedList(ep1)
    MethodAddingEndpointsToExemptedList(ep2)
Else
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep1, method))
    _ExemptEndpoints.Add(Tuple.[New](Of String, Method)(ep2, method))
End If


You could go a step further and create a list of the endpoints and then use a foreach loop to add them to the list of Exempted endpoints.