If you are not very well versed with what a Web API is, in simple terms its a dotnet based RESTful service. Follow us for the latest Microsoft Visual Studio.In this post, we will see how we can quickly get a dotnet Web API running on a Mac. Build apps and games using. This repository ('Code - OSS') is where we (Microsoft) develop the Visual Studio Code product together with the community.Not only do we work on code and issues here, we also publish our roadmap, monthly iteration plans, and our endgame plans.This source code is available to everyone under the standard MIT license.The latest Tweets from Visual Studio for Mac (VisualStudioMac). Visual Studio Code - Open Source ('Code - OSS') The Repository.Nuget is the package manager for dotnet libraries. To install that,Now, to create the web api project we require, run the below commandThis brings us with the option to select the type of asp.net project we want to create as shown below. Select the web API application as highlighted? What type of application do you want to create? Web API Application? What's the name of your ASP.NET application? demo-web-apiCreate demo-web-api/Properties/launchSettings.jsonCreate demo-web-api/Controllers/ValuesController.csYour project is now created, you can use the following commands to get goingDotnet build (optional, build will also happen when it's run)Step 2 : Restoring the dependent packagesThe web api project scaffolded would be dependent on multiple other libraries which can be pulled from Nuget. For our purpose, we need to use aspnet generator.
Visual Studio Web Application Free To UseSince there is no Visual Studio for non-windows platforms, you are free to use any editor of your choice (Atom/Sublime/Vim/Emacs etc.,) I personally use VS Code. To invoke the get method, from any rest client, hit the url Step 5 : Understanding the project structureThis should have been the second step after we scaffolded the project, but I just changed the order to first see the output and then analyze the code. Press Ctrl+C to shut down.As you can see in the last two lines, the app is hosted under a webserver and running at the port 5000.The scaffolded project creates a single controller called ValuesController which exposes a few get/post/put/delete methods. NETCoreApp,Version=v1.0Content root path: /Users/z066157/SampleProjects/dotnetSamples/sample-webapi/demo-web-apiNow listening on: Application started. Path: /Users/z066157/SampleProjects/dotnetSamples/sample-webapi/demo-web-api/project.lock.json/Users/z066157/SampleProjects/dotnetSamples/sample-webapi/demo-web-api/project.jsonOnce the dependent packages are restored, we can run the application by using the below commandProject demo-web-api (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missingCompiling demo-web-api for.How do I change the default port of 5000 ? The asp.net core application are hosted under a web server called Kestrel Where is this app hosted as there is no IIS on MAC ? The launch.json and tasks.json are VS Code specific ones that help in debugging and executing the tasks like build, test etc., To debug the dotnet core/asp.net core apps using VS Code refer to my earlier post. The project will have the below set of folders and files within it.The annotated files are the primary ones that we should know of.By default, asp.net core apps following attribute routing. What is the default routing that is used ? Urls = http : //localhost:5001/ If you would like to give the port dynamically while running the app, run the app using below argumentsDotnet run - server. M audio fast track driver for macAs the below attribute indicates, any route with api/values will resolve to the methods in this controllerPublic class ValuesController : ControllerThat’s pretty much it for running the first app □ More details on asp.net core web apps in future posts.
0 Comments
Leave a Reply. |
AuthorTony ArchivesCategories |