Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPRequest #3

Merged
merged 14 commits into from
Jun 22, 2021
Prev Previous commit
Next Next commit
http request example
  • Loading branch information
orsinium committed Jun 22, 2021
commit 53e38ab346fc30b5d998311affdfff20902aaf4a
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Build all:

```bash
python3 -m pip install -r requirements.txt
python3 build_all.py hello
python3 build_all.py
```
18 changes: 18 additions & 0 deletions examples/http_request/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import "github.com/life4/gweb/web"

func main() {
window := web.GetWindow()
doc := window.Document()
doc.SetTitle("Making HTTP requests")

// make request
req := window.HTTPRequest("GET", "https://httpbin.org/get")
resp := req.Send(nil)

header := doc.CreateElement("pre")
header.SetText(string(resp.Body()))
body := doc.Body()
body.Node().AppendChild(header.Node())
}
18 changes: 11 additions & 7 deletions examples/index.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
categories:
- name: "DOM"
- name: DOM
items:
- name: "hello"
- name: hello
info: 'a small "hello world": set title, create element, add element onto the page.'
- name: "styling"
- name: styling
info: "how to set CSS attributes for an object."
- name: events
info: how to handle events like mouse movement.
Expand All @@ -16,7 +16,7 @@ categories:
how to dynamically load CSS (on example of
[Bootstrap](https://getbootstrap.com/))
and do something when it is ready.
- name: "Canvas"
- name: Canvas
items:
- name: triangle
info: '"hello world" for `<canvas>`: make black background and draw a red triangle.'
Expand All @@ -36,12 +36,16 @@ categories:
classic video game (famous because of clone
[Arkanoid](https://en.wikipedia.org/wiki/Arkanoid))
with a bit more natural (hence annoying) physic.
- name: "Audio"
- name: Audio
items:
- name: "oscilloscope"
- name: oscilloscope
info: "a small example of visualization of an audio from the user microphone."
- name: "piano"
- name: piano
info: >
play MIDI music! A good example of rendering sounds. Based on
[Simple synth keyboard](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Simple_synth)
MDN example.
- name: Networking
items:
- name: http_request
info: how to make an HTTP request
2 changes: 0 additions & 2 deletions web/http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ func (resp HTTPResponse) Body() []byte {
if raw.IsNull() {
return nil
}
// arraybuffer
println(raw.String())
raw = resp.window.Get("Uint8Array").New(raw)
dec := make([]byte, raw.Length())
js.CopyBytesToGo(dec, raw.Value)
Expand Down