Custom API Endpoints: streamlining your architecture
Blog post from SurrealDB
SurrealDB 3.0 introduces a significant feature called DEFINE API, which allows developers to create custom API endpoints directly within the SurrealQL query language, simplifying the traditional three-layer architecture of client, middleware, and database into a more streamlined client-to-database interaction. This enhancement reduces infrastructure complexity, improves performance, and facilitates management, as demonstrated in a real-world scenario where rate limits for guest users in a social application are efficiently managed using this new feature. By incorporating middleware functions such as api::timeout, developers can control server time for guest users, while the DEFINE API statement specifies API endpoints, ensuring that data is returned according to defined criteria. SurrealDB also supports custom middleware functions, enabling developers to enhance API responses further, and with the power of API design integrated into the database, users can redefine architectural possibilities without needing additional frameworks.