C# Backend Server
Configure Project
- First install the library from
nuget
and add it to your project.
<PackageReference Include="Dapi" Version="1.0.0"/>
- Import Dapi's library in your code.
using Dapi;
using Dapi.Products;
using Dapi.Response;
using Dapi.Types;
- Create a Dapi app with your App Secret
namespace TestConsoleApp {
public class TestClass {
private DapiApp myApp;
public TestClass() {
myApp = new DapiApp("YOUR_APP_SECRET");
}
}
}
Configure SDK Server
-
Follow the steps in Configure Project first in order to obtain and import the library.
-
Our code will basically update the request to add your app's
appSecret
to it, and forward the request to Dapi, then return the result.
namespace TestConsoleApp {
public class TestClass {
public void HandlerFunc(string requestBodyJson, ICollection<KeyValuePair<string, string>> requestHeaders) {
var resp = myApp.handleSDKRequest(requestBodyJson, requestHeaders);
//resp = myApp.handleSDKRequest(requestBodyJson); // or with no headers
// do something with the resp
}
}
}
Complete example
You need to replace the placeholder in this code snippet(appSecret
).
For set-up instructions follow the documentation here.
using Dapi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace DapiSDKExample
{
public class Startup
{
public static DapiApp dapiApp = new("YOUR_APP_SECRET");
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.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
Updated 9 months ago