Giter VIP home page Giter VIP logo

myapiconsumer's Introduction

๐Ÿš€ ๐Ÿน My API Consumer

Go

This repository does various data retrievals for trusted sources automatically. It reads data from an input, makes a request, and records the result in a different file.

๐Ÿงฒ Environment Setup

๐Ÿ› ๏ธ Needed tools

  1. Go 1.20 (recommended)

๐Ÿƒ๐Ÿป Application execution

  1. Make sure to download all Needed tools
  2. Clone the repository
git clone https://github.com/dasalgadoc/MyApiConsumer.git
  1. Build up go project
go mod download
go get .
  1. Make a config.yaml file in ./configs In ./configs/secure_config.yaml has an example. Setup the data source clients and provide the location and name of input data.

The config files the following structure

Father Node Description Possible values / Example
- io Describes Input parameters Father node
io location Relative path where input can be found ./file_exchange/
io file_name Input filename (without extension) input
- clients Array with following elements, to describe each rest client Father node
clients name Name to invoke the client api-shazam
clients type Resource type, see configs.go Resource_XXX constants GetRestApi / PostRestApi
clients path HTTP URL for client (without headers) * https://shazam.p.rapidapi.com/shazam-events/list
clients headers Array with following elements, to describe each header
header :HEADER KEY: Header name : header value 'X-RapidAPI-Key': 'SIGN-UP-FOR-KEY'

* Note about defining URIs:

If your URL contains path parameters, you may specify them with their names within curly brackets in the clients[n].path property. For instance: http://example.com/movies/{movie_name}

Make sure a column with these parameters exists in your input file. The next section contains further information on this input file.

  1. Create an input file, in config.yaml file, you specified the property io.file_name. This property is a file where you specific the input data to be processed.

Csv files are one choice; the first row contains the name of each parameter, and each row contains one execution that defines all the parameters.

Example:

move_name year query
split 2016 casting
Inception 2010 rating

The .csv file columns can be used like path parameters, query variables or both.

Json Body

You can use the first column on the input file to specify a JSON BODY. Just call the header as "JSON_BODY" and each row the json in string format.

Example:

JSON_BODY move_name year query
{"key":"value"} split 2016 casting
{"key":"value"} Inception 2010 rating

In this case, the first column will be treated like a Body in JSON format and no like a parameter.

  1. Run the API
go run cmd/cli/main.go
  1. You'll see various errors since not enough parameters were provided; the correct form is as follows.
go run cmd/cli/main.go <DATA SOURCE>

This project use the following flags:

  • inputter: Input file type (default "csv")
  • outputter: Output file type (default "json")

Note: No more clients are specified, but this code is extensible.

Thats why you don't need to specify the flags, but you can if you want to change the default values.

go run cmd/cli/main.go -inputter <INPUT FILE TYPE> -outputter <OUTPUT FILE TYPE> <DATA SOURCE>

For instance:

go run cmd/cli/main.go api_engine_beta

or

go run cmd/cli/main.go -inputter csv -outputter json api_engine_beta 

A helper script is provided to run the API:

chmod +x runner.sh
./runner.sh

myapiconsumer's People

Contributors

dasalgadoc avatar

Watchers

 avatar

Forkers

dsalgadoc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.