-
-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Sample * change the reference of the Projects --------- Co-authored-by: Benjamin Howarth <322383+benjaminhowarth1@users.noreply.github.com>
- Loading branch information
1 parent
5fe5ce5
commit 00dde43
Showing
13 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.852 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryWithSDKandRefitService", "sampleUsngLocalApi\LibraryWithSDKandRefitService\LibraryWithSDKandRefitService.csproj", "{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestApiForTest", "sampleUsngLocalApi\RestApiforTest\RestApiForTest.csproj", "{1A2E3E56-878E-4D2D-89D3-626DB0825120}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleSampleUsingLocalApi", "sampleUsngLocalApi\ConsoleApplication\ConsoleSampleUsingLocalApi.csproj", "{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{97A0AF3F-830B-4067-BFC3-0BA7AC6851E7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1A2E3E56-878E-4D2D-89D3-626DB0825120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1A2E3E56-878E-4D2D-89D3-626DB0825120}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1A2E3E56-878E-4D2D-89D3-626DB0825120}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1A2E3E56-878E-4D2D-89D3-626DB0825120}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D7F3EC64-7473-4FD3-AB05-D7BE55009BE3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {ACEEE495-B3D1-4788-9EE2-C33449109B85} | ||
EndGlobalSection | ||
EndGlobal |
12 changes: 12 additions & 0 deletions
12
samples/sampleUsngLocalApi/ConsoleApplication/ConsoleSampleUsingLocalApi.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibraryWithSDKandRefitService\LibraryWithSDKandRefitService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using LibraryWithSDKandRefitService; | ||
using Refit; | ||
|
||
namespace ConsoleSampleUsingLocalApi | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello World!"); | ||
HttpClient _client = new HttpClient | ||
{ | ||
BaseAddress = new Uri("http://localhost:61868") | ||
}; | ||
IRestService _restApiService = RestService.For<IRestService>(_client); | ||
Console.WriteLine("Enter from the following numbers to access the APIs,\n1 for get ,\n2 for get with argument, \n3 for post,\n4 for put, \n5 for Delete \n"); | ||
while (true) | ||
{ | ||
int choice = Int32.Parse(Console.ReadLine() ?? "6"); | ||
switch (choice) | ||
{ | ||
case 1: | ||
var result1 = _restApiService.GetWithNoParameter().Result; | ||
Console.WriteLine(result1); | ||
break; | ||
case 2: | ||
var result2 = _restApiService.GetWithParameter(4).Result; | ||
Console.WriteLine(result2); | ||
break; | ||
case 3: | ||
var result3 = _restApiService.PostWithTestObject(new ModelForTest()).Result; | ||
Console.WriteLine(result3); | ||
break; | ||
case 4: | ||
var result4 = _restApiService.PutWithParameters(4, new ModelForTest()).Result; | ||
Console.WriteLine(result4); | ||
break; | ||
case 5: | ||
var result5 = _restApiService.DeleteWithParameters(5).Result; | ||
Console.WriteLine(result5); | ||
break; | ||
default: | ||
Console.WriteLine("Bhai Please Enter valid if you are really serious"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/IRestService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Refit; | ||
|
||
namespace LibraryWithSDKandRefitService | ||
{ | ||
public interface IRestService | ||
{ | ||
[Get("/api/values")] | ||
Task<string> GetWithNoParameter(); | ||
|
||
[Get("/api/values/{id}")] | ||
Task<string> GetWithParameter([AliasAs("id")] int id); | ||
|
||
[Post("/api/values")] | ||
Task<string> PostWithTestObject([Body] ModelForTest modelObject); | ||
|
||
[Put("/api/values/{id}")] | ||
Task<string> PutWithParameters([AliasAs("id")] int id, [Body] ModelForTest modelObject); | ||
|
||
[Delete("/api/values/{id}")] | ||
Task<string> DeleteWithParameters([AliasAs("id")] int id); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...les/sampleUsngLocalApi/LibraryWithSDKandRefitService/LibraryWithSDKandRefitService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Refit" Version="4.8.14" /> | ||
</ItemGroup> | ||
|
||
</Project> |
7 changes: 7 additions & 0 deletions
7
samples/sampleUsngLocalApi/LibraryWithSDKandRefitService/ModelForTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace LibraryWithSDKandRefitService | ||
{ | ||
public class ModelForTest | ||
{ | ||
public string TestVariable { get; set; } | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
samples/sampleUsngLocalApi/RestApiforTest/Controllers/ValuesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using LibraryWithSDKandRefitService; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace RestApiforTest.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ValuesController : ControllerBase | ||
{ | ||
// GET api/values | ||
[HttpGet] | ||
public ActionResult<string> Get() | ||
{ | ||
return "Get Api with no argument was Called"; | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet("{id}")] | ||
public ActionResult<string> Get(int id) | ||
{ | ||
return "Get Api was called"; | ||
} | ||
|
||
// POST api/values | ||
[HttpPost] | ||
public ActionResult<string> Post([FromBody] ModelForTest testObject) | ||
{ | ||
return "Post Api was Called"; | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut("{id}")] | ||
public ActionResult<string> Put(int id, [FromBody] ModelForTest testObject) | ||
{ | ||
return "Put Api was called"; | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete("{id}")] | ||
public ActionResult<string> Delete(int id) | ||
{ | ||
return "Delete Api was Called"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace RestApiforTest | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
samples/sampleUsngLocalApi/RestApiforTest/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61868", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"RestApiforTest": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"applicationUrl": "http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
samples/sampleUsngLocalApi/RestApiforTest/RestApiForTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibraryWithSDKandRefitService\LibraryWithSDKandRefitService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace RestApiforTest | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/sampleUsngLocalApi/RestApiforTest/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |