gosexy / rest Goto Github PK
View Code? Open in Web Editor NEWThe rest package helps you creating clients for HTTP APIs with Go.
Home Page: https://menteslibres.net/gosexy/rest
The rest package helps you creating clients for HTTP APIs with Go.
Home Page: https://menteslibres.net/gosexy/rest
Hello,
maybe you could add method returning body as io.Reader.
What for? Well, html package http://godoc.org/code.google.com/p/go.net/html (moved here from exp/html
) for Parse request us to provide io.Reader.
Now we need to:
import "bytes"
import "code.google.com/p/go.net/html"
...
rawDoc, _ := client.Get(values).Do()
// Parse the HTML into nodes
root, err := html.Parse(bytes.NewReader(rawDoc))
Maybe something like this would be shorter:
import "code.google.com/p/go.net/html"
...
rawDoc, _ := client.Get(values).Body()
// Parse the HTML into nodes
root, _ := html.Parse(rawDoc)
Best regards,
Dobrosław Żybort
Hello,
if I try do get image, library will add unnecessary /
to requested url.
package main
import(
"fmt"
"github.com/gosexy/rest"
)
func main(){
url := "http://stackoverflow.com/favicon.ico"
client := rest.New(url)
// Get URL response body
_, err := client.Get(nil).Do()
fmt.Println("Request url:", client.Request.URL.String())
if err != nil {
fmt.Println(err)
}
if client.Response.StatusCode != 200 {
errorText := fmt.Sprintf("Expecting 200, got %d\n",
client.Response.StatusCode)
fmt.Println(errorText)
}
}
output will be:
Request url: http://stackoverflow.com/favicon.ico/
Expecting 200, got 404
Can you fix that?
Best regards,
Dobrosław Żybort
I often find myself submitting JSON payloads to REST API's, but this library currently only allows for payloads in the form of url.Values.
Are PR's welcome?
The response is only unmarshaled if kind is a struct or a map. Why not a slice?
If you're open to a PR, I'd be happy to submit one with a test?
Sample:
client := rest.New("http://example.com/")
and now
client.Get(url.Values{
"page": {"4"},
}).Do()
Will get http://example.com/
client.To("/").Get(url.Values{
"page": {"4"},
}).Do()
Will get http://example.com/?page=4
Best regards,
Dobrosław Żybort
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.