https://github.com/imdrasil/http_method_emulator
Simple HTTP method emulator for form submitted data.
https://github.com/imdrasil/http_method_emulator
crystal-language http
Last synced: 7 months ago
JSON representation
Simple HTTP method emulator for form submitted data.
- Host: GitHub
- URL: https://github.com/imdrasil/http_method_emulator
- Owner: imdrasil
- License: mit
- Created: 2019-01-04T13:25:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-04T13:49:13.000Z (about 7 years ago)
- Last Synced: 2025-06-17T17:50:45.559Z (8 months ago)
- Topics: crystal-language, http
- Language: Crystal
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http_method_emulator
Simple HTTP method emulator for form submitted data.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
http_method_emulator:
github: imdrasil/http_method_emulator
```
2. Run `shards install`
## Usage
HTML form supports only `GET` and `POST` method. To bring other methods support you can use this shard. This shard will be useful for a web frameworks/libs that have no such functionality (like Kemal or Spider-Gazelle).
```crystal
require "http_method_emulator"
# Add handler to your middlewares
# like for Kemal
add_handler HTTPMethodEmulator::Handler::INSTANCE
```
Also require `"lib/http_method_emulator/assets/http_method_emulator.js"` in your js assets.
Now you can just create `POST` form with hidden field `_method` holding required method.
```html
Make Request
```
JS catches submit event and add query parameter based on form `_method` field (or do nothing if it isn't exist). Handler modifies `POST` request method setting value sent in query `_method` field.
### Configuration
You can specify field name to be used for holding method name. This should be done in two places - crystal and JS.
```crystal
HTTPMethodEmulator.config do |conf|
conf.key = "http_method"
end
```
```js
// Anywhere after js being imported
window.HTTPMethodEmulator.key = "http_method"
```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Roman Kalnytskyi](https://github.com/imdrasil) - creator and maintainer