You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Creating a modern REST API with .NET Core and Azure SQL, using Dapper and Visual Studio Code"
16
+
urlFragment: "azure-sql-db-python-rest-api"
9
17
---
10
18
11
-
# Official Microsoft Sample
19
+
# Creating a REST API with .NET Core and Azure SQL
12
20
13
21
<!--
14
22
Guidelines on README format: https://review.docs.microsoft.com/help/onboard/admin/samples/concepts/readme-template?branch=master
@@ -18,36 +26,122 @@ Guidance on onboarding samples to docs.microsoft.com/samples: https://review.doc
18
26
Taxonomies for products and languages: https://review.docs.microsoft.com/new-hope/information-architecture/metadata/taxonomies?branch=master
19
27
-->
20
28
21
-
Give a short description for your sample here. What does it do and why is it important?
29
+
Thanks to native JSON support, creating a REST API with Azure SQL and .NET Core is really a matter of a few lines of code. Take a look at `app.py` to easy it is!
22
30
23
-
## Contents
31
+
Wondering what's the magic behind? The sample uses the well known [Flask](https://flask.palletsprojects.com/en/1.1.x/) micro-framework and the [flask-restful](https://flask-restful.readthedocs.io/en/latest/) package to easily implement REST APIs. Beside that 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.
24
32
25
-
Outline the file contents of the repository. It helps users navigate the codebase, build configuration and any related assets.
Outline the required components and tools that a user might need to have on their machine in order to run the sample. This can be anything from frameworks, SDKs, OS versions or IDE releases.
39
+
## Add Database Objects
39
40
40
-
## Setup
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:
41
42
42
-
Explain how to prepare the sample once the user clones or downloads the repository. The section should outline every step necessary to install dependencies and set up any settings (for example, API keys and output folders).
43
+
`./SQL/WideWorldImportersUpdates.sql`
43
44
44
-
## Running the sample
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)
45
46
46
-
Outline step-by-step instructions to execute the sample and see its output. Include steps for executing the sample from the IDE, starting specific services in the Azure portal or anything related to the overall launch of the code.
47
+
## Run sample locally
47
48
48
-
## Key concepts
49
+
Make sure you have [.NET Core 3.0](https://dotnet.microsoft.com/download) SDK installed on your machine. Clone this repo in a directory on our computer and then configure the connection string in `appsettings.json`.
49
50
50
-
Provide users with more context on the tools and services used in the sample. Explain some of the code that is being used and how services interact with each other.
51
+
If you don't want to save the connection string in the `appsettings.json` file for security reasons, you can just set it using an environment variable:
Check out more samples to test all implemented verbs here:
111
+
112
+
[cUrl Samples](./Sample-Usage.md)
113
+
114
+
## Deploy to Azure
115
+
116
+
Now that your REST API solution is ready, it's time to deploy it on Azure so that anyone can take advantage of it. A detailed article on how you can that that is here:
117
+
118
+
-[Deploying Python web apps to Azure App Services](https://medium.com/@GeekTrainer/deploying-python-web-apps-to-azure-app-services-413cc16d4d68)
119
+
-[Quickstart: Create a Python app in Azure App Service on Linux](https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash)
120
+
121
+
The only thing you have do in addition to what explained in the above articles is to add the connection string to the Azure Web App configuration. Using AZ CLI, for example:
Just make sure you correctly set `$appName` and `$resourceGroup` to match your environment and also that the variable `$ConnectionStrings__DefaultConnection` as also been set, as mentioned in section "Run sample locally". An example of a full script that deploy the REST API is available here: `azure-deploy.sh`.
135
+
136
+
## Learn more
137
+
138
+
If you're new to .NET and want to learn more, there are a lot of tutorial available on the [Microsoft Learn](https://docs.microsoft.com/en-us/learn/browse/?products=dotnet) platform. You can start from here, for example:
0 commit comments