Professional Documents
Culture Documents
How To Quickly Create A Simple REST API For SQL Server Database - by Luc Lamontagne - Vooban's Tech Stories - Medium
How To Quickly Create A Simple REST API For SQL Server Database - by Luc Lamontagne - Vooban's Tech Stories - Medium
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.
Server initialization
*Note: Make sure the SQL Server Browser windows service is running.
Ex .: http://localhost:8081/customers/
executer-select.js
hosted with ❤ by GitHub view raw
Ex .: http://localhost:8081/customers/1
executer-filtrer.js
hosted with ❤ by GitHub view raw
Ex .: http://localhost:8081/customers/1/orders
stored-proc.js
hosted with ❤ by GitHub view raw
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
And then make the REST calls in a Web browser, a tool like Postman or, if you prefer not leaving your console, use curl with a
command like:
https://medium.com/voobans-tech-stories/how-to-quickly-create-a-simple-rest-api-for-sql-server-database-7ddb595f751a 3/3