Types and API schema


#1

So I’m starting work on a serverless component with AWS API gateway and AWS Lambda. I was exploring apistar 0.6 because I find interesting having Types to validate the input body the lambdas receive but I have some doubts on how both the types and the schema work:

  • Is there something to ensure consistency between the schema and the type? I see schema as a generic way to define your API where you can also set constraints for the data going in. Now suppose you defined a type for that input request where I define again the input fields but with further constraints. Am I forced to keep consistency between both or there is something to generate the schema from types, or the types from a schema or to check things make sense between both?
  • I don’t see anything to validate an input request against the schema you have defined in your API. Are you supposed to do this only with types?
  • With the current state, I don’t see any use case for the API schema apart from describing your API, am I right? Is the validation of the request with the schema supposed to be done with an external third party package?

Sorry if my questions are not clear, kind of brainstorming here and trying to make up my mind on how this would look like in the project I’m working :).


#2

I’m not sure about AWS API Gateway with Lambda, but I created FastAPI to solve that.

It is heavily inspired by previous versions of APIStar, when it was an API server framework (current versions don’t have the framework parts).

It is based on and fully compatible with Starlette, APIStar’s creator (Tom Christie) next/current/continuation project. The type validation and handling parts are done with Pydantic.

With FastAPI you declare your types using standard Python type hints. And get validation, serialization, OpenAPI schemas, and automatic API documentation UI.

It also has Dependency Injection, security, etc.

https://fastapi.tiangolo.com/


#3

Sorry, but I don’t see how this relates with “I’m starting work on a serverless component with AWS API gateway and AWS Lambda” that I mentioned in the beginning :slight_smile:


#4

Fair point.

I was referring exclusively to the rest:

  • ensure consistency between schema and type
  • validation of input data
  • etc

[…] kind of brainstorming here […]

I guess I was sort of brainstorming too :slightly_smiling_face:


#5

Thanks for the response, but I have the specific need of using those and I’m trying to make up my mind on how the schemas and the type system are supposed to be combine in apistar :stuck_out_tongue: