ducthinh2111 / weekend-project

0 stars 0 forks source link

Microservice integration language #13

Open ducthinh2111 opened 2 weeks ago

ducthinh2111 commented 2 weeks ago

A language like SQL that abstract the way we interact with microservices

Requirement

A feature is the combination of multiple REST API, provide a language to query, chain those REST calls with ease. The idea is based on the RESTful principle in which a resource is a piece of information that can be selected, inserted, updated. Because of this princible, we don't need to care about the "how", we only need to care about the "what". Actually, we must know the "how" at the first time. :)

Usecases

Select data

students = select * from Student where name = "John Doe"
studentIds = select id from Student where age = 18

Configuration

[
  {
    "resource": "Student",
    "select": {
      "url": "localhost:8080/students",
      "httpMethod": "POST",
      "where": {
        "type": "requestBody",
        "value": {
          "name": "$name",
          "id": "$id",
          "age": "$age"
        }
      }
    }
  }
]

Insert data

registration = {
  "studentId": "1",
  "subjectId": "2"
}
response = insert into Registration data $registratrion                

Configuration

[
  {
    "resource": "Registration",
    "insert": {
      "url": "localhost:9999/registration",
      "httpMethod": "PUT"
    }
  }
]

Combine together

studentIds = select id from Student where name = "John Doe"

registration = {
  "studentId": $students[0],
  "subjectId": "2"
}
response = insert into Registration data $registratrion
print(response)
[
  {
    "resource": "Student",
    "select": {
      "url": "localhost:8080/students",
      "httpMethod": "POST",
      "where": {
        "type": "requestBody",
        "value": {
          "name": "$name",
          "id": "$id",
          "age": "$age"
        }
      }
    }
  },
  {
    "resource": "Registration",
    "insert": {
      "url": "localhost:9999/registration",
      "httpMethod": "PUT"
    }
  }
]