The script from “http://localhost:8080/static/app.js” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.
And indeed, when I check the headers content type in the browser it is not set. How can set it in Cask? I tried naivelyscript(
type:= "text/javascript", src := "/static/app.js")
but it didn't make the warning disappear.
initialize()
in a cask Routes object, it will traverse all methods defined in the object and derive routing information for all methods annotated with an "endpoint" annotation (common endpoints are defined in thecask.endpoints
package, for example cask.get
). This information is contained in an RoutesEndpointMetadata
object and will be used by the final http request routing mechanism (essentially the code that instructs the webserver how to map HTTP requests to method calls)
I just tried the new version on 3.0 and I can't replicate com-lihaoyi/cask#30 any longer. I might as well close it.
However, one thing that struck me is that cask returns a 405 — method not allowed for undefined routes, if the method has not been used for at least one other route. It seems like this should be 404 instead?
DispatchTrie[Map[String, …]]
. It's the old structure inverted basically.
Hi! I am new to both Scala and Cask. I am creating a small solution using Cask to run on a local machine and need a way to start and stop the server on an ad-hoc basis.
Based on the examples in the Cask documentation, it seems that Cask is designed to always start automatically (either by extending cask.MainRoutes with the route definitions or extending cask.Main to include multiple route definitions).
Is there a way I can embed Cask into an application, from which I can control starting and stopping it as required?
:point_up: Edit: @lihaoyi: Hi! I am new to Scala and have been looking everywhere for something like Flask in Scala and Cask seems like the best minimalistic option.
Is something like what the below code does possible in Cask and if so how can I implement it? Please help!
app = Flask(name)
@app.route("/get_emp_info", methods = ['POST'])
def get_employee_record():
input_data = json.loads(request.get_json())
out_data = input_data .to_dict(orient='records')
return jsonify(out_data)
if name == "main":
app.run(host='0.0.0.0', port=6123)
Even if you can provide some link that does something very close to this, that'd be helpful. I'd basically want to be able to run it as a Scala RESTful application.
request: cask.Request
How can we read this if it is a json? like in python requests.get_json()
You can access the request's body and give it to your JSON parser, for example
@cask.get("/")
def foo(req: cask.Request) = {
val json = upickle.default.read[ujson.Value](req.bytes)
...
}
However, there are more idiomatic ways to read JSON in cask. The two that come to mind are:
bytes
method is implemented right in the request class https://github.com/com-lihaoyi/cask/blob/master/cask/src/cask/model/Params.scala#L20