How do you POST data to a database via URL?

5.1k views Asked by At

I need to create a public API for my application that can receive a single POST request. More specifically, I need to give users the ability to post data to my database -- the user would be another dev shop and they would be posting a LOT of data, so I can't ask them to log into my site and start filling out forms. I realize POST data is typically consumed via the body, not query params (this is GET).

However, I know a lot of public API's out there do this (e.g. https://developer.flightstats.com/api-docs/alerts/v1. If you look at this site and create a 'flight rule', they're saving your call and returning JSON when your parameters return true). What is best practice for this?

I'm currently using Express w/ Sequelize, and PostgresQL.

Question: Is there a way to send a POST request via URI parameters, and more importantly, is there a safe way to do this? And, if there isn't, what is the best way for a user to post data to my database without filling out a form?

1

There are 1 answers

2
sumit On BEST ANSWER

Your client dont need to fill up the form , they can call your restfulapi . You need to make restful api server

See the sample below for the restful api client

$.ajax({
    type: 'POST',
    url: '/url',
    data:  JSON.stringify({name: 'jonas',"age":30}),
    success: function(data) { 
        alert('success');
       },
    contentType: "application/json",
    dataType: 'json'
});

Check this How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?

also check this What exactly is RESTful programming?

For security you can use basic auth / digest auth or any other custom authentication based your needs