Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    jodersky
    @jodersky
    strange, the bytes method is implemented right in the request class https://github.com/com-lihaoyi/cask/blob/master/cask/src/cask/model/Params.scala#L20
    gaminricks87
    @gaminricks87:matrix.org
    [m]
    for spark i require scala 2.12 and cask latest version i require scala 2.13
    I think bcoz of older version this is not working for me
    Simon Parten
    @Quafadas

    The cask documentatino suggests that a decorator could be used to automagically serialise responses as JSON.
    "
    but you could make it e.g. automatically serialize returned objects to JSON responses via your favorite library, or serialize
    "
    Now, I've gotten this far..

      class writeToDoList(val path: String, val methods: Seq[String])
        extends cask.HttpEndpoint[Seq[Todos], Seq[String]]{    
    
        def wrapFunction(ctx: cask.Request, delegate: Delegate) = {
          delegate(Map()).map{num =>
            cask.Response(upickle.default.write(num))
          }
        }
    
        def wrapPathSegment(s: String) = Seq(s)
    
        type InputParser[T] = cask.endpoints.QueryParamReader[T]
      }

    But obviously, the end goal is extends cask.HttpEndpoint[T, Seq[String]], unfortunately, I can't seem to get the implicit in scope.

    The compiler says "implementation limitation, argument lists more than length 1 are ignored", if I try to add an implicit argument to the decorator class.
    Any suggestions?
    Otherwise, I'd have to write a decorator per return type :-/...

    pingbat
    @pingbat
    Are there any examples of using Cask with a ScalaJS frontend?
    pingbat
    @pingbat
    And with autowire and boopickle if possible! :-)
    Li Haoyi
    @lihaoyi
    @Quafadas IIRC how it works for uPickle is that it takes some type and then an implicit conversion to that type, and the implicit conversion takes the typeclass
    presumably you can do the same thing?
    Simon Parten
    @Quafadas
    @lihaoyi thankyou. I had to squint at this on and off for quite some time, but I think I have what I want now based on your hint.
    k0ala
    @k0ala
    hi all, I have a noob question about cask. I modified the MinimalApplication (0.7.8) to run on port 8484, and can only connect to it on localhost (from within the Ubuntu 20.04 VM where cask is running), but not from outside. However, if I run another http server (such as a with python -m http.server 8484) I can connect fine. Any hints?
    k0ala
    @k0ala
    Ah, I notice that if I override host to "0.0.0.0" I can access from the outside. Not sure if that's recommended, but at least it allows me to try out cask which was my objective :)
    k0ala
    @k0ala
    I am trying to create a route to upload an image file, but so far it's not working: @cask.postForm("/upload") def uploadFile(image: cask.FormFile) = { image.fileName }
    This yields an error when trying to post: scala> requests.post("http://localhost:8080/upload", data=java.nio.file.Paths.get("cat1.jpg")) requests.RequestFailedException: Request to http://localhost:8080/upload failed with status code 400 Unable to parse form data: java.lang.NullPointerException: Cannot invoke "io.undertow.server.handlers.form.FormDataParser.parseBlocking()" because the return value of "io.undertow.server.handlers.form.FormParserFactory.createParser(io.undertow.server.HttpServerExchange)" is null
    Any hints?
    1 reply
    Li Haoyi
    @lihaoyi
    @k0ala looking at the test suite https://github.com/com-lihaoyi/cask/blob/f3fd29a9206cee465812a80fe6bd04c6c63500c2/example/formJsonPost/app/test/src/ExampleTests.scala#L42-L48, cask.FormFile requires you to use the requests.MultiPart data structure to upload, rather than a raw data =
    1 reply
    k0ala
    @k0ala
    @lihaoyi thank you! I guess it doesn't help that I am an http and web noob (in addition to being a cask noob), I only know scala and decided it was time to learn how to make a website :) Btw, do you plan to refresh the "hands-on-scalajs" website sometime? It is very nicely written but outdated
    Li Haoyi
    @lihaoyi
    (the test suite has a lot of good stuff in general; basically every route in every example has a test case that calls it, and AFAIK all of them should pass)
    haha yeah I can tell, localhost vs 0.0.0.0 is something I'd expect non-scala-web-developers to know :)
    I don't have any concrete plans for updating hands-on-scala-js; I'm still a bit burnt out writing hands-on-scala-programming in 2019-2020 era, so not sure I'd be able to pick up a big project like that
    I wrote hands-on-scala-js when my curiosity was stronger, my standards were lower, and my non-work responsibilities were much fewer haha
    k0ala
    @k0ala
    yeah that's understandable, it blows my mind how many things you've produced
    Li Haoyi
    @lihaoyi
    it could definitely do with a refresh, e.g. using Mill instead of SBT, using Cask instead of Akka-HTTP, using DefinitelyScala facades, using some other OSS projects like Slinky,
    k0ala
    @k0ala
    that sounds awesome ;)
    Li Haoyi
    @lihaoyi
    nope
    k0ala
    @k0ala
    In the meantime I figured out how to upload an image :) I ended up using the raw cask.Request as you suggested. Now I am struggling with the notion of "being logged in", i.e. only allowing users access if they have successfully entered their password. If you have any tutorial/example on this, I am all ears!
    (I went through some AWS Cognito tutorial, so I could use that for the login part. What remains unclear to me is how to use the token or code that is returned by Cognito.)
    k0ala
    @k0ala
    I got a bit of education on JWT tokens, here is how I think it might work with Cognito: 1) user gets sent to Cognito login, receives a token. 2) scalaJS saves the token and adds it to every request header going forward. 3) cask validates the token at every request. Does that sound reasonable? Or am I heading in the wrong direction?
    k0ala
    @k0ala
    I guess I should ask this question in the scala-js/scala-js gitter instead
    lakinwecker
    @lakinwecker
    Good morning, hope everyone is doing well. I'm somewhat new to Scala development, but am tinkering around in using it for web stuff (coming from the python/django world). I'm using scalatags, and am replacing a very simple very ancient php site which has very little server side processing. I like the simplicity of Cask, but am running into issues doing simple form processing using it. For example, if I make a handler which expects a radio button value, but the user submits without the radio button, the resulting page is a 400, rather than something I can handle to display the appropriate error message. I realize that most people do this sort of form submission in JS these days, but I'd like to know how to handle these sorts of things within cask. Does anyone have a recommended method for taking a POST with a urlencoded body and doing some very basic validation (required fields, etc) and turning it into a case class instance or a list of error messages?
    I tried googling for some libraries, and didn't find much, and I've read the cask documentation and couldn't figure it out. Where I ended up was: https://gist.github.com/lakinwecker/b53b59f09c6653e93b14f9e4364c28a2 but if the cabins value is missing from the POST, then cask returns a 400 instead of calling this method with a None for the cabins option.
    Li Haoyi
    @lihaoyi
    @lakinwecker could you try adding a default value = None to your optional parameter see if that can make it happy
    Simon Miles
    @drsimonmiles

    Hello. I've been trying out Cask and got an HTTP server with a Scala.js front-end working without problems, and all seems great. I then wanted to try out Websockets but have got stuck. I tried copying verbatim the first example from the codebase as a starting point:
    https://github.com/com-lihaoyi/cask/blob/master/example/websockets/app/src/Websockets.scala
    but I get compilation errors.

    case cask.Ws.Text("") => channel.send(cask.Ws.Close())
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor

    From looking at the code, I understand that WsActor inherits from Castor's BaseActor (via SimpleActor) and the latter's send method requires an implicit sourcecode fileName and line. I don't understand what these could be in the context of Websockets (but I'm quite new to Websockets).
    I tried running the websockets example test from the Cask codebase, in case it was something odd in my own setup, but hit another problem doing that. I think it's a separate Mill-related question so I'll omit details.
    Any suggestion how I might be getting the compilation error above?

    Li Haoyi
    @lihaoyi
    are you on Scala 3?
    feels like there's some dependency scala version conflicts
    Simon Miles
    @drsimonmiles
    Ah yes, sorry I should have said that, I am using Scala 3
    Simon Miles
    @drsimonmiles
    I've added dependency on com.lihaoyi::castor:0.2.0 and it appears to compile fine now. Thanks again.
    k0ala
    @k0ala
    I suppose the documentation about getRawParams is no longer valid? https://com-lihaoyi.github.io/cask/#extending-endpoints-with-decorators
    k0ala
    @k0ala
    Can I make cask log with logback?
    lakinwecker
    @lakinwecker

    @lakinwecker could you try adding a default value = None to your optional parameter see if that can make it happy

    This is so obvious in hindsight, why didn't I try this?

    k0ala
    @k0ala
    How should I specify the implicit params FileName and Line for castor actors?
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor
    Simon Miles
    @drsimonmiles

    How should I specify the implicit params FileName and Line for castor actors?
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor

    @k0ala That was the problem I raised above, I think. I fixed it (at least for compilation) by adding a dependency on a newer version of castor than the one used by cask, com.lihaoyi::castor:0.2.0

    k0ala
    @k0ala
    @drsimonmiles ah yes, thanks!
    k0ala
    @k0ala
    Does somebody have an example on how to configure cask to log with logback?
    Jared Neil
    @JaredNeil
    Is there an example or existing decorator like postJson, but that uses uPickle to parse to a case class? I'm thinking something like how you can set up MainArgs to parse to custom types.
    In use @jsonApi(TodoRoutes.getATodo) def aTodo(id: Int): Option[Todos] = { myDB.aTodo(id).headOption } which is a cask route... the decorator wraps the result into a response.
    Christian Ternus
    @ternus
    Hi! I'm trying to get the examples to work, but I'm running into this error:
    [$]> mill -w app.runBackground
    Compiling /Users/ternus/src/cask-0.7.12/example/minimalApplication/build.sc
    Cannot resolve app. Did you mean all?
    If I do mill resolve _, it shows:
    [$]> mill resolve _
    [1/1] resolve
    all
    clean
    inspect
    par
    path
    plan
    resolve
    show
    shutdown
    version
    visualize
    visualizePlan
    Pathikrit Bhowmick
    @pathikrit
    Is there a way to run cask server in watch mode using sbt? Something like sbt> ~server/runMain Server ? This will hot reload the server on code changes?
    2 replies
    kurgansoft
    @kurgansoft
    Is it possible to use Cask with livejs?
    The problem is that livejs emits head requests to check if a file has changed, but cask returns with a 405 error.
    Is there a simple way to enable head requests for static files(cask.staticFiles annotation)?