tobinbradley/dirt-simple-postgis-http-api

Creating a POST route

Closed this issue · 4 comments

Got the API up and running on a new server for someone and they want to POST data to a table.

Is that something that the API can currently do?

Great. I'll have a go at figuring it out.

If you look at any route, you'll find the method declaration like this:

// create route
module.exports = function (fastify, opts, next) {
  fastify.route({
    method: 'GET',

If you changed that method to 'POST', it would listen for POSTs.

The other part you'll have to change is the schema. Instead of describing 'params', which are GET parameters, you'd describe 'body', which are POST parameters. I haven't done that, but I think they look about the same.

Note that this library isn't exactly SQL-injection safe, and there's no user authentication system, so easy does it :). You might want to check the ecosystem for an authentication plugin.

Thanks Tobin. Extremely helpful as always.

Duly noted about SQL injection. Though you're other current customer seems to think he has that sussed ;)