grip-framework / grip Goto Github PK
View Code? Open in Web Editor NEWThe microframework for writing powerful web applications.
Home Page: https://grip-framework.github.io/docs/
License: MIT License
The microframework for writing powerful web applications.
Home Page: https://grip-framework.github.io/docs/
License: MIT License
@grkek I took a look into the source code, and it seems it is using older approaches, or solutions that were necessary with an older version of the standard library.
I want to contribute some improvements, but I only open PR if I know that it will get attention.
For example, Grip::Parsers::ParameterBox::AllParamsType
is unnecessary as it's the same as the JSON::Any::Type
in the latest version of the standard library.
Also, the standard library includes a HTTP::Request#query_params
in the latest version.
There are some places in the documentation that could be improved also.
Is there any approach to deal with it within reach?
May with the pipeline or a new middlewire?๐
Hi,
I'm checking the example on https://grip-framework.github.io/docs/error_handling/ and when I run the test app, I get the next error:
There was a problem expanding macro 'error'
Code in src/napake.cr:39:5
39 | error 403, ForbiddenController
^
Called macro defined in lib/grip/src/grip/dsl/macros.cr:82:7
82 | macro error(error_code, resource)
Which expanded to:
1 | @exception_handler.handlers[{{error_code}}] = {{resource}}.new
^---------
Error: undefined macro variable 'error_code'
I also tested the code(custom error pages) with my old examples from version 1.1.1 and the results are practically the same.
br, uz
Hello I'm working on having grip ready for TechEmpowerBenchmarks
I want to use all the cores available, so I was wondering if there is an option for passing
reuse_port: true
when running the application.
Example of what we do at Kemal
Thanks!
Hi @grkek,
I am not sure wheter there is an official place in crystal
to find shards, but https://crystalshards.org/shards/search?q=grip seems to list the 0.28.6
Regards,
Is your feature request related to a problem? Please describe.
Helper methods to handle file upload/download requests
Helper methods or documentation to handle streaming video/audio
Currently there's no documentation for how to upload/download files
Describe the solution you'd like
Have something similar to Kemal's send_file
helper method in Controller class and documentation of example usages.
Describe alternatives you've considered
Additional context
It needs to handle uploading/downloading files and possibly even streaming for a video/audio website.
What is the difference between inheriting my exception controllers from Grip::Controllers::Exception
and Grip::Exceptions::Base
?
Hi! Love your work on the framework! Great design decisions!
I've tried to install and run on local, and run into trouble:
$ crystal -v
Crystal 1.9.2 [1908c816f] (2023-07-19)
LLVM: 15.0.7
Default target: aarch64-apple-darwin
$ shards install
Resolving dependencies
Fetching https://github.com/grip-framework/grip.git
Fetching https://github.com/luislavena/radix.git
Fetching https://github.com/crystal-loot/exception_page.git
Fetching https://github.com/sija/backtracer.cr.git
Using radix (0.4.1)
Using backtracer (1.2.2)
Using exception_page (0.3.1)
Using grip (2.0.2)
$ crystal run src/demo.cr
ld: library not found for -lssl (this usually means you need to install the development package for libssl)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with exit status 1: cc "${@}" -o /Users/tolik.kukul/.cache/crystal/crystal-run-demo.tmp -rdynamic -L/Users/tolik.kukul/.asdf/installs/crystal/1.9.2/embedded/lib -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre2-8 -lgc -levent -liconv
I've reinstalled openssl and tried to set the var like they suggest on Crystal website, but still error. Please help! Thank you!
IO doesn't flush on close
class Index < Grip::Controller::Http
def get(context)
text(
context,
"-"*10000 + "!"
)
end
end
class Application < Grip::Application
def initialize
get "/", Index
end
end
app = Application.new
app.run
Expected behavior:
using curl http://localhost:3000/ the response should be closed and the ! should be returned
Actual behavior:
using curl http://localhost:3000/ the response is not closed and the ! is never printed
Reproduces how often:
always
I narrowed it done to the extension on response
The original implementation shows
https://github.com/crystal-lang/crystal/blob/5999ae29b/src/http/server/response.cr#L222
But the grip redefined method does not flush the IO.
Looking at the methods they seem pretty similar, is this extension still required?
So I'm having a problem passing the context.fetch_body_params function to context.json()
I wrote the code just like in the documentation example:
def get(context : Context) : Context
params =
context
.fetch_body_params
context
.json(params)
end
And it's giving me this error:
I'm sorry if it's my own mistake
On Windows, when serve_static is set true, behaviors to request for local resources will lead to a series of errors, including 304 resp status to a request for static files, none response for requests to obtain data from database etc.
grip/src/grip/handlers/static.cr
Line 29 in be4ac9f
File.expand_path("/whois", "/") => C:\whois
Hi,
first of all I would like to thank you for awesome work on the Grip project.
I followed the example #17 and figured out that Grip::Pipes::Log show/print only HTTP status 200 requests. Is there an option to print unsuccessful requests through pipeline logger?
Describe the bug
When trying to run a Grip application, it can't be compiled because the method final
is not defined for OpenSSL::Digest
.
To Reproduce
Steps to reproduce the behavior:
crystal init app <app_name>
shards.yml
, exactly like in the READMEExpected behavior
Have a running Grip server running
Desktop (please complete the following information):
The following code
class Index < Grip::Controllers::Http
def get(context : HTTP::Server::Context)
context
.html("<h1>Hello world ๐</h1>")
.halt
end
Should render <h1>Hello world ๐</h1>
Current rendering: <h1>Hello world รฐ๏ฟฝ๏ฟฝ๏ฟฝ</h1>
In order to do so, the .html()
method could set the default encoding to utf-8
.
In the meantime, skipping the shortcut does the job:
class Index < Grip::Controllers::Http
def get(context : HTTP::Server::Context)
context
.put_resp_header("Content-Type", "text/html; charset=utf-8")
.send_resp("<h1>Hello world ๐</h1>")
.halt
end
Hello, first of all I want to thank you for the awesome work on Grip!
The version I use in my projects is the v0.28.3
, and I recently saw some movement on this repo, leading to release of v1.0.0
recently.
Just got curious about which features and breaking changes there are on this new major version? What are the main differences that v1.0.0
brings in?
Just thought you might want to know since I'm working on adding a different framework and noticed.
grip: In grip.cr:48:14
grip: 48 | class Json < Grip::Controller::Http
grip: ^---------------------
grip: Error: undefined constant Grip::Controller::Http
grip: Did you mean 'Grip::Controllers'?
Process.on_interrupt
was introduced into Crystal API since 1.8.0.
@grkek, I want to catch JSON::SerializationError
without specifying begin โฆ rescue โฆ end
block everywhere.
I read the source, and it seems it's not possible currently.
I am interested in implementing this. I have two ideas. If you agree, I can implement this.
What do you think about changing the @handlers
keys to be the type of Exception
instead of status code?
Currently, custom exceptions have a @status
code, and this is what is matched in the handlers.
I would create a base class Grip::Exception::StatusException < Exception
, then inherit 404Error
, 500Error
, etc.
This is how it would be used:
error 404Error, My404Page
error 500Error, My500Page
error JSON::SerializationError, JsonErrorPage
Another approach could be to rename @handlers
to @status_handlers
, and create an @exception_handlers
too.
Then the matching would be done on exception type. If it is a Grip::Exceptions::Base
, then the current status code matching behavior would activate. This could be done by setting up a handler by default for Grip::Exceptions::Base
, which would decide what page is rendered by matching @status_handlers
using the currently implemented method.
I think this approach could be done without breaking existing code, as the error
macro could decide which handler is set up (status or exception).
error 404, My404Page # This is an Int32, then set up status code handler
error DivisionByZero, MyCalculatorErrorPage # This is an Exception, then set up exception handler
Hello,
I was going through the code looking for how SSL is used internally and I noticed that SHA1 is explicitly required in the project. SHA1 is no longer secure, so can there be a way to choose the hashing method to be used?
Thanks in advance
Hello, I've made spec-grip and I want it to be in grip-framework so, is it possible to add me to the org like that I transfer to grip-framework ?
Thanks! ๐
I couldn't find a solution to serve static files in specified path in Crystal public api. It's a nice feature worth considering. Or anything already works now?
Why does Grip have so ugly method names like context.get_resp_headers("Content-Type")
?
Idiomatic Crystal code should use the indexing syntax: context.response.headers["Content-Type"]
Are there any plans to include a static file server in grip? Similar to how Kemal automatically serves the /public
directory or Phoenix serves the priv/static/
directory.
I might be wrong, but it seems like the route override Proc would instantiate a new controller instance for each request.
The instantiation happens in the override Proc:
Line 49 in 3423a44
When there's no method override, it uses the controller instance saved in the route instance:
Line 37 in 710f5d3
Ideally, the override should also use the controller instance saved in the route instance.
This behavior could be observed with below example server:
require "../src/grip"
class IndexController < Grip::Controllers::Http
def initialize
puts "Initializing Index Controller"
end
def get(context : Context) : Context
puts "info"
context
.put_status(200) # Assign the status code to 200 OK.
.json({"id" => 1}) # Respond with JSON content.
.halt # Close the connection.
end
def index(context : Context) : Context
puts "echo"
id =
context
.fetch_path_params
.["id"]
# An optional secondary argument gives a custom `Content-Type` header to the response.
context
.json(content: {"id" => id}, content_type: "application/json; charset=us-ascii")
end
end
class Application < Grip::Application
def routes
get "/info", IndexController
get "/echo/:id", IndexController, as: :index
end
end
app = Application.new
app.run
The log shows below messages:
Initializing Index Controller
Initializing Index Controller
2022-02-02 07:58:42 UTC [info] listening at http://0.0.0.0:5000.
info
info
info
Initializing Index Controller
echo
Initializing Index Controller
echo
Initializing Index Controller
echo
I think we should avoid instantiating new instances of the controllers for each request.
@grkek
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.