create an http post for every row in a csv file.
The api I was working with was an RPC style framework, not RESTful at all. A ui element accidentally let somebody generate 10000 new records in the database with no easy way to undo that action. This was terribly inconvenient for the user to be forced to manually delete something like 10000 records, at something like 1 minute per deletion.
I built this tool to batch update all the items which had been created based on a csv file generated by having direct access to the database
It was important that the work be done through the application for legal and security reasons, not to mention possible side effects. Manually updating a production DB is a nono.
This tool is highly limited, but I solved the problem by using it, which helped the application users and our business reputation.
given a csv file such as:
client_id,firstname,middlename,lastname
3456,Michael,Wayne,Wilding
3555,Jane,W,Austen
- determine your endpoint.
- The endpoint to update the client info might look like
http://hostname/update-client
- determine the query
- the form data might look like
client_id=###&firstname=string&middlename=string&lastname=string
- in my case I read the api query by performing the operation manually in the browser and taking the params
- buid, install, and run
- the tool will run through every line of the csv document and make a post with the data on each row
so the example from the csv above would look like
/update-client?client_id=3465&firstname=Michael&middlename=Wayne&lastname=Wilding
- build and install by running
go install
- if your environment is setup, you will now be able to run
posty
- run
posty create-config config.json
. - fill in the appropriate fields in the config file.
Notes:
- it includes an array of headers. You can add as many headers as you want. I used it to add the appropriate session cookies so I can authenticate my calls.
- Also, there is a known bug where you cant add more than one cookie or configure the request more fully. My mvp didnt need it so I choose to save that edge case for the future.
- run
posty run /path/to/config.json /path/to/file.csv int rate
- If you run
posty /path/to/csf/file
you will see requests and responses printed to stdout.