usage of AVRO Schemas

Not applicable

will APIGEE support usage of AVRO Schemas.

We need AVRO to validate incoming POST Requests to start with before applying the same to Responses.

1 4 949
4 REPLIES 4

Not applicable

Hi there!

Can you be more specific about your use case here? We don't support AVRO schemas as of now, but, would love to hear about the use case and see if we can provide your inputs to our product team.

Thanks,

Archendra

Not applicable

We need AVRO to validate incoming POST Requests to start with before applying the same to Responses

That capability is not built-in to Apigee Edge. But, it is not too difficult to write custom policies in Edge that do whatever you like. Since there is an Avro library for Python and for Java, I suppose you could write a custom policy to do message validation in either of those languages. Which is your preference?

If you give me a sample schema, and an example data payload or two, I might be able to write up an example for how to do this, for you.

Hi @vinay k kasam

I wrote an example to illustrate how you could do this with a custom policy.

Find the source code on github.

The basic idea is you can parse an inbound Avro payload into a LIst<Map<String,Object>> if you have the Avro Schema. Configuration for the custom policy looks like this:

<JavaCallout name='Java-ParseAvro'>
  <Properties>
    <Property name="schema">{"namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": ["int", "null"]},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}</Property>
  </Properties>
  <ClassName>com.dinochiesa.edgecallouts.AvroParser</ClassName>
  <ResourceURL>java://edge-avro-parse-callout.jar</ResourceURL>
</JavaCallout>

I also built an example API Proxy to demonstrate this custom policy. Invoke it like this:

curl -i -X POST 
    https://ORGNAME-ENVNAME.apigee.net/avro-parser/shred?name=sample 
    --data-binary @example/users.avro

Obviously that payload needs to correspond to the schema you've got configured in the Policy XML.

The Java code is pretty simple, you can view it here. The example API proxy bundle that uses the policy is also on that repo.

Good luck!