Trap ctrl-c and exit nicely

Hello,

Not sure how to trap a ctrl-c, wait for a http request to finish, and
then exit nicely?