Sha256: 818159e53f5a118d4ec2a8d07d836bce9785134d96bb1a08c800058db31c99bd
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
# Ovto.fetch Ovto provides wrapper of [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch), for convenience of calling typical server-side APIs (eg. those generated by `rails scaffold` command.) `Ovto.fetch` returns Opal's Promise object that calls the API with the specified parameters. ## Examples GET ```rb Ovto.fetch('/api/tasks').then{|json_data| p json_data }.fail{|e| # Network error, 404 Not Found, JSON parse error, etc. p e } ``` POST ```rb Ovto.fetch('/api/new_task', 'POST', {title: "do something"}).then{|json_data| p json_data }.fail{|e| # Network error, 404 Not Found, JSON parse error, etc. p e } ``` PUT ```rb Ovto.fetch('/api/tasks/1', 'PUT', {title: "do something"}).then{|json_data| p json_data }.fail{|e| # Network error, 404 Not Found, JSON parse error, etc. p e } ``` ## CSRF tokens You don't need to care about CSRF tokens if the server is a Rails app because `Ovto.fetch` automatically send `X-CSRF-Token` header if the page contains a meta tag like `<meta name='csrf-token' content='....' />`.
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
ovto-0.7.0 | book/api/fetch.md |
ovto-0.6.2 | book/api/fetch.md |
ovto-0.6.1 | book/api/fetch.md |
ovto-0.6.0 | book/api/fetch.md |
ovto-0.6.0.rc1 | book/api/fetch.md |
ovto-0.5.0 | book/api/fetch.md |