Bojjaiah
Bojjaiah

Reputation: 261

Create and Request Array of Azure parameter function

I am trying to create an Array of Azure parameter function, but it's not working for me. For these, I tried below code.

ABCBarCodes Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionApp4
{

    public class ALCBarCodes
    {

        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }

    }

}

Azure Function

using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp4
{
    public static class Function4
    {
        [FunctionName("Function4")]
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "Function4/{ALCBarCodes}")]HttpRequestMessage req, List<ALCBarCodes> list, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // Fetching the name from the path parameter in the request URL
            return req.CreateResponse(HttpStatusCode.OK, list);
        }
    }
}

On this case how can I request the URL?

I tried below URL but it's not working.

http://localhost:7071/api/Function4/1

Any help on this?

Upvotes: 0

Views: 1364

Answers (1)

rajsekhar
rajsekhar

Reputation: 61

Here is the working piece. Please try this

using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

namespace Forum
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
            HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            //dynamic input =await req.Content.ReadAsAsync<dynamic>();

            ALCBarCodes[] input = await req.Content.ReadAsAsync<ALCBarCodes[]>();

            // Fetching the name from the path parameter in the request URL
            return req.CreateResponse(HttpStatusCode.OK, input);
        }
    }
    public class ALCBarCodes
    {
        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }
    }
}

Sample Input:

[
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
}
]

Upvotes: 2

Related Questions