More scala questions - common super class of HttpRequestBuilder and HttpRequestWithParamsBuilder?

I’m trying to figure out how to do this:

`
trait RestfulService {
def method : String


protected def GET = … // returns HttpRequestBuilder
protected def PUT = …
protected def POST = … // returns HttpRequestWithParamsBuilder
protected def formPOST = …
protected def DELETE = …
protected def HEAD = …

def request = method match {
case “GET” => this.GET
case “PUT” => this.PUT
case “POST” => this.POST
case “formPOST” => this.formPOST
case “DELETE” => this.DELETE
case “HEAD” => this.HEAD
case s => throw new Error( "Unexpected request method: " + s )
}
}

`

Then

trait RtdeService extends RestfulService { ... def request = if ( Config.Endpoint.Services.config.getBoolean( "layer7" ) ) super.request .queryParam( "access_token", ACCESS_TOKEN.value ) else super.request .header( "o2_client_id", CLIENT_ID.value ) .header( "o2_scope", CLIENT_SCOPE.value ) .header( "o2_individual_id", USER_NAME.value ) .header( "Cache-Control", "no-cache" ) }

I get a type mismatch on the RtdeService request method at the super.request lines that looks something mind-bending, like this:

`
type mismatch; found : _11 where
type _11 >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: io.gatling.http.request.builder.AbstractHttpRequestBuilder[
_ >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: com.typesafe.scalalogging.slf4j.StrictLogging]
required: io.gatling.http.request.builder.AbstractHttpRequestBuilder[
? >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: io.gatling.http.request.builder.AbstractHttpRequestBuilder[
_ >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: com.typesafe.scalalogging.slf4j.StrictLogging]]
Note: com.typesafe.scalalogging.slf4j.StrictLogging

: ? >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: io.gatling.http.request.builder.AbstractHttpRequestBuilder[
_ >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: com.typesafe.scalalogging.slf4j.StrictLogging]
(and _11 <: io.gatling.http.request.builder.AbstractHttpRequestBuilder[
_ >: io.gatling.http.request.builder.HttpRequestBuilder
with io.gatling.http.request.builder.HttpRequestWithParamsBuilder
<: com.typesafe.scalalogging.slf4j.StrictLogging]),
but class AbstractHttpRequestBuilder is invariant in type B. You may wish to define B as -B instead. (SLS 4.5)
`

I’ve experimented with many different ways of doing the type declaration, but I have not hit upon the right way to do it. Any ideas?

`

`

What your trying to do is simply impossible (at least, not the way you’re trying to implement it)!
Scala is a strongly, statically typed language, meaning that types are resolved COMPILE time.
Yet, you’re trying to determine some types depending on some RUNTIME resolution (matching the request method).
Impedance mismatch, period!

The object of your quest is called Type-Level programming. In the end, you’ll reach enlightenment, but you’re setting on a long journey. Miles Sabin and Runar Oli will be your guides.

So in short, I painted myself into a corner. I need to mop up the paint and start over…

Which takes me back to the way I was originally thinking of doing it:

trait RestfulService …
trait RestfulGET extends RestfulService …

But then I need to define an RtdeAuth trait which extends … what? It is looking like this might work:

class RtdeAuth[R <: RestfulService]( desc : String ) extends RestfulService { … }

Then I define my individual services like so:

def GET = new RtdeAuth[RestfulGET] ( “description” ) with PagingParameters { path = “/v1/something” }

Readable?