Skip to content

Commit

Permalink
Increment to version 0.4.0 and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wcsanders1 committed Feb 23, 2019
1 parent ef50905 commit 2b81723
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MockApiHub

[![Go Report Card](https://goreportcard.com/badge/github.com/wcsanders1/MockApiHub)](https://goreportcard.com/report/github.com/wcsanders1/MockApiHub) [![BuildStatus](https://travis-ci.org/wcsanders1/MockApiHub.svg?branch=master)](https://travis-ci.org/wcsanders1/MockApiHub) [![codecov](https://codecov.io/gh/wcsanders1/MockApiHub/branch/master/graph/badge.svg)](https://codecov.io/gh/wcsanders1/MockApiHub) [![License](https://img.shields.io/badge/license-mit-blue.svg)](https:/githubusercontent.com/wcsanders1/MOckApiHub/master/LICENSE) [![GoDoc](https://img.shields.io/badge/go-documentation-darkblue.svg)](https://godoc.org/github.com/wcsanders1/MockApiHub) ![Version](https://img.shields.io/badge/version-0.3.0-darkred.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/wcsanders1/MockApiHub)](https://goreportcard.com/report/github.com/wcsanders1/MockApiHub) [![BuildStatus](https://travis-ci.org/wcsanders1/MockApiHub.svg?branch=master)](https://travis-ci.org/wcsanders1/MockApiHub) [![codecov](https://codecov.io/gh/wcsanders1/MockApiHub/branch/master/graph/badge.svg)](https://codecov.io/gh/wcsanders1/MockApiHub) [![License](https://img.shields.io/badge/license-mit-blue.svg)](https:/githubusercontent.com/wcsanders1/MOckApiHub/master/LICENSE) [![GoDoc](https://img.shields.io/badge/go-documentation-darkblue.svg)](https://godoc.org/github.com/wcsanders1/MockApiHub) ![Version](https://img.shields.io/badge/version-0.4.0-darkred.svg)

## Overview

Expand Down Expand Up @@ -64,11 +64,16 @@ keyFile = ""
file = "customers.json"
method = "GET"
allowCORS = true

[endpoints.createCustomer]
path = "customers"
method = "POST"
HTTPStatusCode = 201
```

As shown above, logging for a mock API is configured the same way as for the hub server. If you want a mock API to use TLS and the hub server is also using TLS, you can leave the certificate and key file entries in the mock API configuration empty, in which case the certificate and key of the hub server will be used. Files containing the data that a mock API returns need to be placed in the same directory as the mock API's configuration file.

A mock API can have a `baseURL`, which applies to all of its endpoints. Each endpoint of a mock API must have an entry in the `endpoints` section of the configuration file. Files containing the data that a mock API returns need to be placed in the same directory as the mock API's configuration file. In the example above (assuming the hub server is running on `localhost`) the following `GET` request will return whatever is in the `accounts.json` file: `http://localhost:5001/customersapi/accounts`. If you want to enforce valid JSON for a particular endpoint, you can add `enforceValidJSON = true` to that endpoint's configuration. Note that a mock endpoint does not need to return anything on the response body for the request to be successful. Setting `allowCORS = true` allows all origins, headers, and methods.
A mock API can have a `baseURL`, which applies to all of its endpoints. Each endpoint of a mock API must have an entry in the `endpoints` section of the configuration file. Files containing the data that a mock API returns need to be placed in the same directory as the mock API's configuration file. In the example above (assuming the hub server is running on `localhost`) the following `GET` request will return whatever is in the `accounts.json` file: `http://localhost:5001/customersapi/accounts`. If you want to enforce valid JSON for a particular endpoint, you can add `enforceValidJSON = true` to that endpoint's configuration. Note that a mock endpoint does not need to return anything on the response body for the request to be successful. Setting `allowCORS = true` allows all origins, headers, and methods. If you do not specify an `HTTPStatusCode` or if you provide an invalid value for that property, status code `200` will apply.

If you want to have an argument as part of a mock API's URL, just put a colon in front of the route fragment. Also, a query string can be added to any HTTP request to a mock API and its values and keys will be logged. For example, the `getCustomerBalances` endpoint in the configuration above can be hit with the following URL, `http://localhost:5001/customersapi/customers/12345/balances?page=2&size=50`, which will return whatever is in `customers.json`. If logging is enabled, the request will be logged like this (note the logging of the `id` variable in `params`, as well as the keys and values in the query string):

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
hubFlags.Visit(func(f *flag.Flag) {
if f.Name == "v" {
*showVersion = true
fmt.Println("v0.3.0")
fmt.Println("v0.4.0")
}
})

Expand Down

0 comments on commit 2b81723

Please sign in to comment.