Shivpratap1999 / apiHitter

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.
*

About

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


Languages

Language:Go 100.0%