https://github.com/kwangsing3/http_methods_golang
http_methods_golang is a tiny wrapper for implementing HTTP request methods with Golang, and designed for reuse in every projects which don't have to implement those METHODS, when a simple communication is in need.
https://github.com/kwangsing3/http_methods_golang
golang http request wrapper
Last synced: 3 months ago
JSON representation
http_methods_golang is a tiny wrapper for implementing HTTP request methods with Golang, and designed for reuse in every projects which don't have to implement those METHODS, when a simple communication is in need.
- Host: GitHub
- URL: https://github.com/kwangsing3/http_methods_golang
- Owner: kwangsing3
- License: mit
- Created: 2021-07-24T12:49:41.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-04T16:58:30.000Z (over 3 years ago)
- Last Synced: 2024-12-31T12:52:53.129Z (5 months ago)
- Topics: golang, http, request, wrapper
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http_method_golang
**http_methods_golang** is a tiny wrapper for implementing HTTP request methods with Golang, and designed for reuse in every projects which don't have to implement those **METHODS**, when a simple communication is in need.# Methods
HTTP Protocol defined serveal request methods for gaining data and contents using Network.
| METHOD | STATUS |
| --------|---------|
| GET |√|
| POST |√|
| HEAD |--|
| PUT |√|
| DELETE |√|
| CONNECT |--|
| OPTIONS |--|
| TRACE |--|
| PATCH |--|| OPERATE | STATUS |
| --------|---------|
| READ FILE |√|
| WRITE FILE |√|# Install
```sh
go get github.com/kwangsing3/http_methods_golang
```# Usage
* ## GET
1. Would return HTML file if request target is website.
2. Would return bytes if request a data.
``` go
//GET: To get data from GET method, need to wait for respone
//: request address.
func GET(url string) ([]byte, error)
```
* ## POST
1. Mostly use for encrypt request or requested using ``````.
2. May using for change server status or special request (Depends on the design).
``` go
//POST: To get data from POST method, need to wait for respone
//: request address.
//: The query you want to do, mostly are json, but still depends on the server you request.
func POST(url string, query []byte) ([]byte, error)
```* ## DELETE
``` go
//DELETE: http Delete method request
func DELETE(url string) ([]byte, error)
```
* ## PUT
``` go
//PUT: http Delete method request
func PUT(url string, content string) ([]byte, error)
```
# Example
```go
package mainimport (
"encoding/json"
"fmt"
HMG "github.com/kwangsing3/http_methods_golang"
)func main() {
/***GET request***/
dataGET, errG := HMG.GET("https://example.com")
if errG != nil {
fmt.Println(errG.Error())
}fmt.Println(string(dataGET))
/*** POST request***/
query := struct {
Msg string
}{
Msg: `New Message`, //query Struct depends on the server you request.
}
bytequery, _ := json.Marshal(query)
dataPOST, errP := HMG.POST("https://example.com", bytequery)
if errP != nil {
fmt.Println(errP.Error())
}fmt.Println(string(dataPOST))
return
}```