Pitcher is an open-source API caller tool designed to simplify the process of making HTTP requests and testing APIs. Similar to Postman, it provides a user-friendly programatic interface for crafting requests, inspecting responses, and organizing your API workflow.
It's Golang code centric, with no UI, no versioning and no copy and pasting. The real developer productivity tool.
- User-Friendly Interface: Intuitive UI makes it easy to create and send HTTP requests.
- Multiple Request Methods: Support for various HTTP methods including GET, POST, PUT, DELETE, etc.
- Environment Variables: Define and utilize environment variables for flexible testing.
- Authentication: Support for different authentication methods including Basic Auth, OAuth, JWT, etc.
- Logs: Support for different authentication methods including Basic Auth, OAuth, JWT, etc.
- Option1: To install Pitcher, simply clone the repository and update the "cmd/main.go" to your needs or
- Option2: Using go get
go get github.com/zamariola/pitcher
and the create the project importing it
package main
import (
"flag"
"fmt"
pitcher "github.com/zamariola/pitcher"
)
var local = map[string]string{
"host": "https://jsonplaceholder.typicode.com",
}
func main() {
// Define the client with the global processors
client := pitcher.NewClientWithProcessors(
//Read and write session that expires once it finishes
pitcher.NewMemoryRWSession(local),
//Slice of global (every request) Pre Processors that set ups the session and variables
//if neeeded
[]pitcher.PreProcessorFunc{
//Pre processor that reads the "jwt_token" variable and adds to the Request Header
pitcher.JWTAuth,
},
//Slice of Post Processor that manipulates the response and could extract values from
//response to the session for reusage
[]pitcher.PostProcessorFunc{
//Post processor to log the step result
pitcher.LogStepProcessor,
},
)
err := client.Do(
//Fluent API to create a request
//pitcher.GET("<ur>").WithPreProcessors(...PreProcessors).WithPostProcessors(...PostProcessors)
pitcher.GET("/posts").
// Pre processors that prepares the session or update the request before the execution
WithPreProcessors(
pitcher.UpdateSession("jwtToken", "eyJhbGciOiJIUzI1NiIsInR5cC..."),
pitcher.JWTAuth,
).
WithPostProcessors(
//Post processor that extracts the json value from the path 0.id to the session
//variable named "id" so it can be reused in the later steps
//The path extraction is using https://github.com/tidwall/gjson notation
pitcher.Extract("id", "0.id"),
),
//Manually creating the step and the request
pitcher.Step{
Request: &pitcher.Request{
Method: "GET",
// Path reusing the "id" variable extracted in the previous steps
Path: "/posts/${id}",
},
Assertions: []pitcher.AssertionFunc{
pitcher.SuccessAssertion,
},
},
//pitcher.POST("<url>",<body>, <contentType>)
pitcher.POST(
"/posts",
`{"title": "Michael G Scott", "body": "Regional Manager ${randomUUID}", "userId": 1 }`,
"application/json",
).WithPreProcessors(
pitcher.JWTAuth,
).WithPostProcessors(
//Post processor extracting the id again and overriding the previous value
pitcher.Extract("id", "id"),
//Post processor logging the entire payload response
pitcher.LogPayloadProcessor,
),
pitcher.Step{
Request: &pitcher.Request{
Method: "GET",
Path: "/post/${id}",
},
Assertions: []pitcher.AssertionFunc{
pitcher.NotFoundAssertion,
},
},
)
if err != nil {
panic(err)
}
}
We welcome contributions from the community! If you'd like to contribute to Pitcher, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/improvement
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/improvement
). - Create a new Pull Request.
Please make sure to read our Contribution Guidelines before submitting your pull request.
If you encounter any issues or have any questions about Pitcher, feel free to open an issue on GitHub.
Pitcher is licensed under the MIT License.
Pitcher wouldn't be possible without the contributions of the following individuals:
- Leonardo Zamariola: Maintainer.