{"id":13775070,"url":"https://github.com/azure-samples/azure-sql-db-node-rest-api","last_synced_at":"2025-05-11T07:31:48.501Z","repository":{"id":45331675,"uuid":"285681704","full_name":"Azure-Samples/azure-sql-db-node-rest-api","owner":"Azure-Samples","description":"REST API using Node, Azure Functions and Azure SQL","archived":false,"fork":false,"pushed_at":"2021-12-20T16:06:39.000Z","size":73,"stargazers_count":29,"open_issues_count":0,"forks_count":20,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-04-11T17:02:21.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-06T22:13:52.000Z","updated_at":"2024-04-11T17:02:21.628Z","dependencies_parsed_at":"2022-08-28T01:51:41.149Z","dependency_job_id":null,"html_url":"https://github.com/Azure-Samples/azure-sql-db-node-rest-api","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-node-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-node-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-node-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-node-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/azure-sql-db-node-rest-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225027328,"owners_count":17409411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:33.523Z","updated_at":"2024-11-17T10:30:26.647Z","avatar_url":"https://github.com/Azure-Samples.png","language":"TSQL","funding_links":[],"categories":["Code Samples"],"sub_categories":["REST"],"readme":"---\npage_type: sample\nlanguages:\n- nodejs\n- javascript\n- tsql\n- sql\n- json\nproducts:\n- azure\n- vs-code\n- azure-sql-database\n- azure-functions\ndescription: \"Creating a modern REST API with Node and Azure SQL, Azure Functions and Visual Studio Code\"\nurlFragment: \"azure-sql-db-node-rest-api\"\n---\n\n# Serverless REST API with Azure Functions, Node and Azure SQL\n\n![License](https://img.shields.io/badge/license-MIT-green.svg)\n\n\u003c!-- \nGuidelines on README format: https://review.docs.microsoft.com/help/onboard/admin/samples/concepts/readme-template?branch=master\n\nGuidance on onboarding samples to docs.microsoft.com/samples: https://review.docs.microsoft.com/help/onboard/admin/samples/process/onboarding?branch=master\n\nTaxonomies for products and languages: https://review.docs.microsoft.com/new-hope/information-architecture/metadata/taxonomies?branch=master\n--\u003e\n\nThanks to native JSON support, creating a serverless REST API with Azure Functions, Azure SQL and Node is really a matter of a few lines of code. Take a look at `customer/index.js` to see how easy it is!\n\nWondering what's the magic behind? Azure Functions takes care of running the NodeJS code, so all is needed is to get the incoming HTTP request, handle it, send the data as we receive it - a JSON - to Azure SQL and we're done. Thanks to the [native JSON support that Azure SQL provides](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-json-features), it does all the heavy lifting for as so sending data back and forth to the database is as easy as sending a JSON message.\n\n## Install Sample Database\n\nIn order to run this sample, the WideWorldImporters database is needed. Install WideWorldImporters sample database:\n\n[Restore WideWorldImporters Database](https://github.com/yorek/azure-sql-db-samples#restore-wideworldimporters-database)\n\n## Add Database Objects\n\nOnce the sample database has been installed, you need to add some stored procedure that will be called from JavaScript. The SQL code is available here:\n\n`./sql/WideWorldImportersUpdates.sql`\n\nIf you need any help in executing the SQL script, you can find a Quickstart here: [Quickstart: Use Azure Data Studio to connect and query Azure SQL database](https://docs.microsoft.com/en-us/sql/azure-data-studio/quickstart-sql-database)\n\n## Run sample locally\n\nMake sure you add the information needed to connect to the desired Azure SQL database in the `local.settings.json`. Create it in the root folder of the sample using the `.template` file, if there isn't one already. After editing the file should look like the following:\n\n```json\n{\n  \"IsEncrypted\": false,\n  \"Values\": {\n    \"FUNCTIONS_WORKER_RUNTIME\": \"node\",\n    \"AzureWebJobsStorage\": \"UseDevelopmentStorage=true\",\n    \"db_server\": \"\u003cserver\u003e.database.windows.net\",\n    \"db_database\": \"\u003cdatabase\u003e\",\n    \"db_user\": \"NodeFuncApp\",\n    \"db_password\": \"aN0ThErREALLY#$%TRONGpa44w0rd!\"\n  }\n}\n```\n\nwhere `\u003cserver\u003e` and `\u003cdatabase\u003e` have been replaced with the correct values for your environment. Once done that, start local Azure Function host with\n\n```bash\nfunc start\n```\n\nif you are using [Azure Functions Core Tools](https://www.npmjs.com/package/azure-functions-core-tools) or using [Visual Studio Code Azure Function extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions)\n\nFor more info on other options to run Azure Function locally look here:\n\n[Code and test Azure Functions locally](https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-local)\n\nOnce the Azure Function HTTP  is up and running you'll see something like\n\n```text\nNow listening on: http://0.0.0.0:7071\nApplication started. Press Ctrl+C to shut down.\n\nHttp Functions:\n\n        customer: [GET,PUT,PATCH,DELETE] http://localhost:7071/api/customer/{id:int?}\n```\n\nUsing a REST Client (such as [Visual Studio](https://learn.microsoft.com/aspnet/core/test/http-files), [Insomnia](https://insomnia.rest/), [Curl](https://curl.se/docs/httpscripting.html) or PowerShell's [Invoke-RestMethod](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod)), you can now call your API, for example:\n\n```bash\ncurl -X GET http://localhost:7071/customer/123\n```\n\nand you'll get info on Customer 123:\n\n```json\n[\n    {\n        \"CustomerID\": 123,\n        \"CustomerName\": \"Tailspin Toys (Roe Park, NY)\",\n        \"PhoneNumber\": \"(212) 555-0100\",\n        \"FaxNumber\": \"(212) 555-0101\",\n        \"WebsiteURL\": \"http://www.tailspintoys.com/RoePark\",\n        \"Delivery\": {\n            \"AddressLine1\": \"Shop 219\",\n            \"AddressLine2\": \"528 Persson Road\",\n            \"PostalCode\": \"90775\"\n        }\n    }\n]\n```\n\nCheck out more samples to test all implemented verbs here:\n\n[cUrl Samples](./sample-usage.md)\n\n## Debug from Visual Studio Code\n\nDebugging from Visual Studio Code is fully supported, thanks to the [Visual Studio Code Azure Function extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions)\n\n## Deploy to Azure\n\nNow that your REST API solution is ready, it's time to deploy it on Azure so that anyone can take advantage of it. A script `azure-deploy.sh` that uses AZ CLI (so it needs to be executed from a Linux shell. If you don't have one on your machine you can use [Azure Cloud Shell](https://azure.microsoft.com/en-us/features/cloud-shell)) is available within the repo. Just make sure you fill the needed settings into the `local.settings.json` as mentioned before as the script will read the values from there.\n\n```bash\n./azure-deploy.sh\n```\n\nIt will care of everything for you:\n\n- Creating a Resource Group (you can set the name you want by changing it directly in the .sh file)\n- Creating a Storage Account\n- Creating Azure Application Insights\n- Create an Azure Function App\n- Deploying repo code to Azure Function\n\nEnjoy!\n\n# Contributing \n\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\nMore details in the full [Contributing](./CONTRIBUTING.md) page.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fazure-sql-db-node-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure-samples%2Fazure-sql-db-node-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fazure-sql-db-node-rest-api/lists"}