My question is can we manage the extensions.conf and sip.conf using ARI/AMI/AGI? Please point me to the right way. Also, can i restart the asterisk server from the API?
If not then will it be safe if I write all this using some server side script
You can’t manage them using ARI. From AGI if you wrote your own thing that modified the config files you potentially could. AMI has some rudimentary ways to do dialplan stuff, but it is not frequently used.
As @jcolp said, you can do some rudimentary configuration using AMI, or use AGI for create your own call flow, also a good way could be use Asterisk realtime for store configuration files on a DB and then manipulate directly from any compatible DB client