Giter Site home page Giter Site logo

third-party-api-resolver-example's Introduction

Third Party API Resolver

This is an example API resolver which exposes the necessary endpoints so they can in turn be consumed by the builder. It follows the standard layed out in the docs and the accompanying ADR, using a very simple data source as an example.

How to run

You'll need to first install the dependencies with:

npm install

Then you can do

npm run start # it'll build the project first

API

Once again we follow the docs here for each endpoint we expose. We'll explain each one briefly, check the docs and ADR for more info

@GET /registry/:registry-id/address/:address/assets

This endpoint is responsible of returning all assets an address own, for a particular registry. It has a response format it has to follow.

Example

# Try to find assets for an invalid registry
/v1/registry/invalidregistry/address/0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd/assets
{
  "address": "0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd",
  "total": 0,
  "page": 1,
  "next": "",
  "assets": []
}

# Try to find assets for an address that has none
/v1/registry/cryptoregistry/address/0x1bb1c46af05fed1a407d86c468a783d13a1acf7e/assets
{
  "address": "0x1bb1c46af05fed1a407d86c468a783d13a1acf7e",
  "total": 0,
  "page": 1,
  "next": "",
  "assets": []
}

# Try to find assets for a valid registry and a owner that exists
/v1/registry/cryptoregistry/address/0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd/assets

{
  "address": "0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd",
  "total": 1,
  "page": 1,
  "next": "",
  "assets": [
    {
      "id": "0xb794f5ea0ba39494ce839613fffba74279579268:2",
      "amount": 1,
      "urn": {
        "decentraland": "urn:decentraland:matic:collections-thirdparty:cryptoregistry:0xb794f5ea0ba39494ce839613fffba74279579268:2"
      }
    }
  ]
}

@GET /registry/:registry-id/address/:address/assets/:id

This endpoint is responsible of returning a single asset via it's id. It must belong to the regsitry and to the address. It has a response format it has to follow.

Example

# Try to find an asset for an invalid registry
/v1/registry/invalidthings/address/0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd/assets/0xb794f5ea0ba39494ce839613fffba74279579268:2
{
  "id": "0xb794f5ea0ba39494ce839613fffba74279579268:2",
  "amount": 0,
  "urn": {
    "decentraland": ""
  }
}

# Try to find an asset for an address that does not own it
/v1/registry/cryptoregistry/address/0x1bb1c46af05fed1a407d86c468a783d13a1acf7e/assets/0xb794f5ea0ba39494ce839613fffba74279579268:2
{
  "id": "0xb794f5ea0ba39494ce839613fffba74279579268:2",
  "amount": 0,
  "urn": {
    "decentraland": ""
  }
}

# Try to find an asset with an invalid asset id
/v1/registry/cryptoregistry/address/0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd/assets/0xb794f5ea0ba39494ce839613fffba74279579268:44
{
  "id": "0xb794f5ea0ba39494ce839613fffba74279579268:44",
  "amount": 0,
  "urn": {
    "decentraland": ""
  }
}

# Try to find an asset for a valid registry and a owner that owns it
/v1/registry/cryptoregistry/address/0xc04528c14c8ffd84c7c1fb6719b4a89853035cdd/assets/0xb794f5ea0ba39494ce839613fffba74279579268:2
{
  "id": "0xb794f5ea0ba39494ce839613fffba74279579268:",
  "amount": 1,
  "urn": {
    "decentraland": "urn:decentraland:matic:collections-thirdparty:cryptoregistry:0xb794f5ea0ba39494ce839613fffba74279579268:2"
  }
}

@GET /registry/:registryId/owners-bloom-filter

This endpoint is responsible for returning a bloom filter comprising all the owners a registry has. For more information on why this endpoint is required you can check this diagrams document

This example uses the BloomFilter implementation of @ethereumjs/vm library to get all the available owners and return a JSON response that can later be used like this:

import Bloom from '@ethereumjs/vm/dist/bloom'

const url = '/v1/registry/cryptoregistry/owners-bloom-filter'

const response = await fetch(url).then((res) => res.json())
const filter = new Bloom(Buffer.from(response.data, 'hex'))

filter.has('0xf8af76decf64f4164f0c8c9d38f3fb4781e61c0f') // true
filter.has('0xd357f1ff39dd407b5F383806E025eFeF5ea00F9E') // false

Example

# Try to get the bloom filter for an invalid registry
/v1/registry/invalidstuff/owners-bloom-filter
{
  data: ""
}

# Try to get the bloom filter for a valid registry
/v1/registry/cryptoregistry/owners-bloom-filter
{
  "data": "00100000000000000000000000000000080010000800000000000000000000000080000000000000000000000000000000000000000000000000000000000002000000000004000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000800000000040000000000000000000000000000020000000000000280000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040040000000000000000000000000000000010000000000000000000000000000"
}

third-party-api-resolver-example's People

Contributors

cyaiox avatar dependabot[bot] avatar lautaropetaccio avatar menduz avatar nachomazzara avatar nicosantangelo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.