Skip to content

apiHitter package is to send request on any URL form go program without any 3rd party dependencies

Notifications You must be signed in to change notification settings

Shivpratap1999/apiHitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apiHitter

Simple go 1.18 package to consume an API through http methods like GET,POST,PUT,DELETE,PACH etc using Curl. (created to consume APIs, and could be used for other things) Methods build API URL params, connection url, and parse expected JSON response.

Installation

run command
go get "github.com/Shivpratap1999/apiHitter"
After running above comond import package :

import "github.com/Shivpratap1999/apiHitter"

How to use apiHItter

payload := apiHitter.Payload{
URL: "http.google.com",
Method: "POST", //this may any http method
Body: Data, // Data should by of type []byte
ContentType: apiHitter.ApplicationJSON,
}
resp, err := payload.Hit()
if err != nil || resp.Code != http.StatusOK{
fmt.Printf(error:%s while hitting url",err )
}
fmt.Printf("Response Code: %d and Response Data :%s",resp.Code , resp.Data")
//resp is of type HitResponse which is a custom response having fields - Data []byte ,resp *http.Response , Code int.
*

Releases

No releases published

Packages

No packages published

Languages