|
1 |
| -# Project Name |
| 1 | +--- |
| 2 | +page_type: sample |
| 3 | +languages: |
| 4 | +- nodejs |
| 5 | +- javascript |
| 6 | +- tsql |
| 7 | +- sql |
| 8 | +products: |
| 9 | +- azure |
| 10 | +- vs-code |
| 11 | +- azure-sql-database |
| 12 | +- azure-functions |
| 13 | +description: "Creating a modern REST API with Python and Azure SQL, using Flask and Visual Studio Code" |
| 14 | +urlFragment: "azure-sql-db-node-rest-api" |
| 15 | +--- |
2 | 16 |
|
3 |
| -(short, 1-3 sentenced, description of the project) |
| 17 | +# Creating a REST API with Azure Functions, Node and Azure SQL |
4 | 18 |
|
5 |
| -## Features |
| 19 | + |
6 | 20 |
|
7 |
| -This project framework provides the following features: |
| 21 | +<!-- |
| 22 | +Guidelines on README format: https://review.docs.microsoft.com/help/onboard/admin/samples/concepts/readme-template?branch=master |
8 | 23 |
|
9 |
| -* Feature 1 |
10 |
| -* Feature 2 |
11 |
| -* ... |
| 24 | +Guidance on onboarding samples to docs.microsoft.com/samples: https://review.docs.microsoft.com/help/onboard/admin/samples/process/onboarding?branch=master |
12 | 25 |
|
13 |
| -## Getting Started |
| 26 | +Taxonomies for products and languages: https://review.docs.microsoft.com/new-hope/information-architecture/metadata/taxonomies?branch=master |
| 27 | +--> |
14 | 28 |
|
15 |
| -### Prerequisites |
| 29 | +Thanks 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! |
16 | 30 |
|
17 |
| -(ideally very short, if any) |
| 31 | +Wondering 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) does all the heavy lifting so sending data back and forth to the database is as easy as sending a JSON message. |
18 | 32 |
|
19 |
| -- OS |
20 |
| -- Library version |
21 |
| -- ... |
| 33 | +## Install Sample Database |
22 | 34 |
|
23 |
| -### Installation |
| 35 | +In order to run this sample, the WideWorldImporters database is needed. Install WideWorldImporters sample database: |
24 | 36 |
|
25 |
| -(ideally very short) |
| 37 | +[Restore WideWorldImporters Database](https://github.com/yorek/azure-sql-db-samples#restore-wideworldimporters-database) |
26 | 38 |
|
27 |
| -- npm install [package name] |
28 |
| -- mvn install |
29 |
| -- ... |
| 39 | +## Add Database Objects |
30 | 40 |
|
31 |
| -### Quickstart |
32 |
| -(Add steps to get up and running quickly) |
| 41 | +Once the sample database has been installed, you need to add some stored procedure that will called from Python. The SQL code is available here: |
33 | 42 |
|
34 |
| -1. git clone [repository clone url] |
35 |
| -2. cd [respository name] |
36 |
| -3. ... |
| 43 | +`./sql/WideWorldImportersUpdates.sql` |
37 | 44 |
|
| 45 | +If 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) |
38 | 46 |
|
39 |
| -## Demo |
| 47 | +## Run sample locally |
40 | 48 |
|
41 |
| -A demo app is included to show how to use the project. |
| 49 | +Make 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: |
42 | 50 |
|
43 |
| -To run the demo, follow these steps: |
| 51 | +```json |
| 52 | +{ |
| 53 | + "IsEncrypted": false, |
| 54 | + "Values": { |
| 55 | + "FUNCTIONS_WORKER_RUNTIME": "node", |
| 56 | + "AzureWebJobsStorage": "UseDevelopmentStorage=true", |
| 57 | + "db_server": "<server>.database.windows.net", |
| 58 | + "db_database": "<database>", |
| 59 | + "db_user": "NodeFuncApp", |
| 60 | + "db_password": "aN0ThErREALLY#$%TRONGpa44w0rd!" |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
44 | 64 |
|
45 |
| -(Add steps to start up the demo) |
| 65 | +where `<server>` and `<database>` have been replaced with the correct values for your environment. Once done that, start local Azure Function host with |
46 | 66 |
|
47 |
| -1. |
48 |
| -2. |
49 |
| -3. |
| 67 | +```bash |
| 68 | +func start |
| 69 | +``` |
50 | 70 |
|
51 |
| -## Resources |
| 71 | +if 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) |
52 | 72 |
|
53 |
| -(Any additional resources or related projects) |
| 73 | +For more info on other options to run Azure Function locally look here: |
54 | 74 |
|
55 |
| -- Link to supporting information |
56 |
| -- Link to similar sample |
57 |
| -- ... |
| 75 | +[Code and test Azure Functions locally](https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-local) |
| 76 | + |
| 77 | +Once the Azure Function HTTP is up and running you'll see something like |
| 78 | + |
| 79 | +```text |
| 80 | +Now listening on: http://0.0.0.0:7071 |
| 81 | +Application started. Press Ctrl+C to shut down. |
| 82 | +
|
| 83 | +Http Functions: |
| 84 | +
|
| 85 | + customer: [GET,PUT,PATCH,DELETE] http://localhost:7071/api/customer/{id:int?} |
| 86 | +``` |
| 87 | + |
| 88 | +Using a REST Client (like [Insomnia](https://insomnia.rest/), [Postman](https://www.getpostman.com/) or curl), you can now call your API, for example: |
| 89 | + |
| 90 | +```bash |
| 91 | +curl -X GET http://localhost:7071/customer/123 |
| 92 | +``` |
| 93 | + |
| 94 | +and you'll get info on Customer 123: |
| 95 | + |
| 96 | +```json |
| 97 | +[ |
| 98 | + { |
| 99 | + "CustomerID": 123, |
| 100 | + "CustomerName": "Tailspin Toys (Roe Park, NY)", |
| 101 | + "PhoneNumber": "(212) 555-0100", |
| 102 | + "FaxNumber": "(212) 555-0101", |
| 103 | + "WebsiteURL": "http://www.tailspintoys.com/RoePark", |
| 104 | + "Delivery": { |
| 105 | + "AddressLine1": "Shop 219", |
| 106 | + "AddressLine2": "528 Persson Road", |
| 107 | + "PostalCode": "90775" |
| 108 | + } |
| 109 | + } |
| 110 | +] |
| 111 | +``` |
| 112 | + |
| 113 | +Check out more samples to test all implemented verbs here: |
| 114 | + |
| 115 | +[cUrl Samples](./sample-usage.md) |
| 116 | + |
| 117 | +## Debug from Visual Studio Code |
| 118 | + |
| 119 | +Debugging 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 |
| 120 | + |
| 121 | +## Deploy to Azure |
| 122 | + |
| 123 | +TDB |
| 124 | + |
| 125 | +## Connection Resiliency |
| 126 | + |
| 127 | +TDB |
| 128 | + |
| 129 | +## Learn more |
| 130 | + |
| 131 | +TDB |
| 132 | + |
| 133 | +## Contributing |
| 134 | + |
| 135 | +This project welcomes contributions and suggestions. Most contributions require you to agree to a |
| 136 | +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
| 137 | +the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. |
| 138 | + |
| 139 | +When you submit a pull request, a CLA bot will automatically determine whether you need to provide |
| 140 | +a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions |
| 141 | +provided by the bot. You will only need to do this once across all repos using our CLA. |
| 142 | + |
| 143 | +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
| 144 | +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
| 145 | +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
0 commit comments