Skip to content

Conversation

@ghik
Copy link
Contributor

@ghik ghik commented Jul 17, 2018

ghik and others added 30 commits June 27, 2018 14:11
commons-jetty: implemented handler for new rest
…vlet and RestHandler

commons-jetty: added unit tests for RestHandler
…methods the same way as returning failed futures
Copy link

@Starzu Starzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed before:

  1. It would be great to provide sensible defaults for all REST annotations in order to make it possible to use a clean RPC trait as a REST interface. I think we should also add a test to ensure that is possible.
  2. We should provide some kind of DefaultRpcAndRestApiCompanion to simplify usage of interface in both RPC and REST.

case multiple =>
val pathStr = headers.path.iterator.map(_.value).mkString("/")
val callsRepr = multiple.iterator.map(p => s" ${p.rpcChainRepr}").mkString("\n", "\n", "")
throw new RestException(s"path $pathStr is ambiguous, it could map to following calls:$callsRepr")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You ensure that paths are not ambiguous in line 49, so resolvePath can return Option[ResolvedPath]. Probably you can make ensureUnambiguousPaths and ensureUniqueParams boolean lazy vals and require them to be true inside resolvePath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it makes sense to refactor resolvePath to return Opt/Option

I don't understand why you want validation to be done lazily. I explicitly wanted it to be done eagerly so that it fails fast and can be put into a unit test. Ideally I'd like this validation to be done in compile time but that's impossible in this case.


def empty: HttpBody = Empty

def apply(content: String, mimeType: String): HttpBody =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create a wrapper for mimeType: String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit of overkill to me as it's already wrapped into HttpBody so it's meaning is clear and it's intended to be always used when handling bodies.

final val GET, PUT, POST, PATCH, DELETE: Value = new HttpMethod
}

case class RestHeaders(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a little misleading - it contains not only headers, but also other arguments. What about RestParameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RestParameters is not perfect either because there are also body parameters which are not part of this class. I'm open to other naming suggestions but I couldn't find better.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, RestParameters is not perfect, but it's a little better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I finally decided that RestParameters is better

@ghik
Copy link
Contributor Author

ghik commented Jul 25, 2018

@Starzu

  1. Yes, that is done. HTTP methods are POST or Prefix by default, depending on their result type. GET parameters are Query by default, other HTTP method parameters are JsonBodyParam by default and Prefix parameters are Path by default. This is all expressed using @methodTag/@paramTag/@tagged meta-annotations on RawRest.

  2. I've set up an infrastructure for that - you'll be able to write a custom companion base class like that relatively easily, without having to write any macros manually - see RpcMacroInstances. However, this should be done outside of commons because it heavily depends on particular use case.

@ghik ghik merged commit 797fd83 into master Jul 25, 2018
@ghik ghik deleted the rpc-rest branch July 25, 2018 10:38
@ghik ghik restored the rpc-rest branch January 11, 2019 12:49
@ghik ghik deleted the rpc-rest branch January 11, 2019 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants