Why use a SQL database when all you really want is a key-value store?
Simple API with Nginx and PostgreSQL
51–60 of 74 posts
Re: Simple API with Nginx and PostgreSQL
#52This article gives a good example of why you SHOULD consider using an existing framework to create a REST API. I see no concern about authentication, authorisation, scalability, protection from SQL injection attacks, nor making the output easily parseable by third-party applications. None of these are issues you can simply say, "I'll deal with that later when it becomes a problem." They are reasons why an existing fr…
Re: Simple API with Nginx and PostgreSQL
#53Interesting. I'd like to see how you implement role based access control and sql injection safeguards. How would you define complex validation schemes? In stored procedures?
Re: Simple API with Nginx and PostgreSQL
#54On an unrelated note, timestamptz is advisable over timestamp.
Timestamptz is one amazing reason to use Postgres over MySQL frankly. Proper time + timezone storage is quite useful.
Re: Simple API with Nginx and PostgreSQL
#55And yes, this approach should only be used for very simple APIs. If you're building something bigger, use a framework.
Re: Simple API with Nginx and PostgreSQL
#56Earlier quoted context omitted.
Timestamptz is one amazing reason to use Postgres over MySQL frankly. Proper time + timezone storage is quite useful.
Postgresql doesn't offer proper timezone storage, or in fact any timezone storage. Timestamptz is just a UTC timestamp that is converted to/from your connection-specified timezone. You completely lose the "what timezone was this originally specified in" data.
Re: Simple API with Nginx and PostgreSQL
#57Great for a quick little hack, but I wouldn't want to maintain that conf file once the project grows.
Well, this is for a very simple REST API and the post acknowledges that much. I mean if this does become a "project", I'm sure it's time to move it to a proper framework, but as you say for a quick hack, it's a pretty nice way to do it (with proper sanitization, of course). I'd also venture that this is an order of magnitude faster and more responsive than a framework so there are definitely some plusses and minuses…
Re: Simple API with Nginx and PostgreSQL
#58Doesn't couchdb accomplish this? (out of box REST API with little config)
Re: Simple API with Nginx and PostgreSQL
#59Doesn't couchdb accomplish this? (out of box REST API with little config)
Exactly. Couchdb is preferable to this for so many reasons. The author is effectively using the Nginx configuration language for server-side scripting. The result ends up looking a lot like a bad PHP crud app. With couchdb, the REST API is already built in.
Re: Simple API with Nginx and PostgreSQL
#60Is this a "look how cool/flexible nginx is!" article or a real proposal about how to do API's?
Hopefully the former. It would be difficult to build anything non-trivial with it. However, I suppose you could build a basic counter or key-value system over HTTP with it.
This looks like a very nice way to build small simple REST APIs especially if you're already using nginx and postgres anyway.