Skip to content

Commit

Permalink
[Hack Update] 015 serverless coach guide tweaks (#823)
Browse files Browse the repository at this point in the history
* Added OpenAI Fundamentals to WTH home page AND linked to it from the archived "002-IntroToAI" hack

* added whitelist file for 002

* updated C2 Coach guide with sample HelloWorld C# code and tip about using CLI to create functions.

* resolved spelling issues
  • Loading branch information
jrzyshr authored Mar 15, 2024
1 parent 204b305 commit b9750e7
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion 015-Serverless/Coach/Solution-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,59 @@
Code: ResourceKindRequireAcceptTerms
```

- If using Codespaces, in order to work with a folder containing a function written in a different language, we must click the "burger" menu on the top left, then Open Folder in New Window, and select the folder with the function. This is because the VS Code extension for Azure Functions assumes the Local Workspace Project to contain functions of the same single language. This may be worked around using [Multi-root workspaces](https://github.com/microsoft/vscode-azurefunctions/wiki/Multiple-function-projects) , but it hasn't been tested in Codespaces with Azure functions
- If using Codespaces, in order to work with a folder containing a function written in a different language, we must click the "hamburger" menu on the top left, then Open Folder in New Window, and select the folder with the function. This is because the VS Code extension for Azure Functions assumes the Local Workspace Project to contain functions of the same single language. This may be worked around using [Multi-root workspaces](https://github.com/microsoft/vscode-azurefunctions/wiki/Multiple-function-projects) , but it hasn't been tested in Codespaces with Azure functions

**TIP:** Students can also use the CLI to create a new function project folder and generate the quickstart code for any language, [like this "Hello World" for C#](https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-csharp?tabs=windows%2Cazure-cli#create-a-local-function-project). Remember to Open VS Code at that folder in order to have an easier user experience with the Azure Functions extension. IF students go down this path, support them as best you can, but you might want to recommend they stick to VS Code if they get stuck.


## Step by Step Instructions
Students are expected to follow this Quickstart:
- [RECOMMENDED: Visual Studio Code](https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp)
- [Visual Studio](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio)

## APPENDIX Hello World code
In case there's a change in the latest VS Code, here's a Hello World example for C# (.NET 8)

```csharp
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace HelloWorldName
{
public class HttpExample
{
private readonly ILogger _logger;

public HttpExample(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HttpExample>();
}

[Function("HttpExample")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

response.WriteString("Hello World!");

return response;
}
}
}
```

You also need a Program.cs entry point at the root, so it works in [Isolated mode](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows)
```csharp
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();

host.Run();
```

0 comments on commit b9750e7

Please sign in to comment.