How to quickly create a simple REST API for SQL Server database
In IT consulting projects, we frequently have to use an existing database. Here’s how to create a simple REST API for a database in SQL Server using Node.js and the two modules Express (a Web framework for Node.js) and mssql (MS SQL Server client for Node.js). Returning results in JSON format that can easily be treated by a web application, mobile, another REST service, etc.
*Note: Make sure the SQL Server Browser windows service is running.
Simple Select query on the Customer table
Simple Select query with a where clause on the CustomerId field
Execute a stored procedure with one parameter
This implementation remains minimalist. But with the information received in the callback, it would be easy to add logging, manage SQL errors, etc.
You can try this example by simply copy the code in a file like server.js and run it with Node.js:
$ node server.js