Quickstart
Automatic Setup
We recommend creating a new Bridge app using create-bridge-app, which sets up everything automatically for you. (You don't need to create an empty directory, create-bridge-app will make one for you.) To create a project, run:
terminalbashnpx create-bridge-app@latest# orpnpm create bridge-app# oryarn create bridge-app
terminalbashnpx create-bridge-app@latest# orpnpm create bridge-app# oryarn create bridge-app
After the installation is complete:
- Run
cd ./your_project_name - Run
npm iorpnpm ioryarn install - Run
npm run devorpnpm devoryarn devto start the development server onhttp://localhost:8080 - Edit
index.tsto start developing your server
For more information on how to use create-bridge-app, you can review the create-bridge-app documentation.
Manual Setup
Installations
Install bridge and zod in your project:
terminalbashnpm install bridge zod# oryarn add bridge zod# orpnpm add bridge zod
terminalbashnpm install bridge zod# oryarn add bridge zod# orpnpm add bridge zod
Create an index.ts file
Complete Bridge App with HTTP
server.tstsimport {handler ,initBridge } from 'bridge';// A handler can set an endpoint and validate user data such as the body, files,// request parameters or headers sent.consthelloEndpoint =handler ({resolve : () => 'Hello World',});// To define the routes for our project, we can create a routes object and place// our handlers inside. The keys of the object correspond to the path.constroutes = {hello :helloEndpoint ,};constport = 8080;constbridge =initBridge ({routes });consthttpServer =bridge .HTTPServer ();httpServer .listen (port , () => {console .log (`Listening on port ${port }`);});
server.tstsimport {handler ,initBridge } from 'bridge';// A handler can set an endpoint and validate user data such as the body, files,// request parameters or headers sent.consthelloEndpoint =handler ({resolve : () => 'Hello World',});// To define the routes for our project, we can create a routes object and place// our handlers inside. The keys of the object correspond to the path.constroutes = {hello :helloEndpoint ,};constport = 8080;constbridge =initBridge ({routes });consthttpServer =bridge .HTTPServer ();httpServer .listen (port , () => {console .log (`Listening on port ${port }`);});
Complete Bridge App with Express
server.tstsimport {handler ,initBridge } from 'bridge';importexpress from 'express';constroutes = {hello :handler ({resolve : () => 'Hello World',}),};constport = 8080;constapp =express ();constbridge =initBridge ({routes });app .use ('',bridge .expressMiddleware ());app .listen (port , () => {console .log (`Listening on port ${port }`);});
server.tstsimport {handler ,initBridge } from 'bridge';importexpress from 'express';constroutes = {hello :handler ({resolve : () => 'Hello World',}),};constport = 8080;constapp =express ();constbridge =initBridge ({routes });app .use ('',bridge .expressMiddleware ());app .listen (port , () => {console .log (`Listening on port ${port }`);});
You can test your endpoint by making an http call to POST http://localhost:8080/hello. Refer to the route documentation for instructions on customizing the HTTP method.
Congratulations, you just launched your first Bridge server! 🥳
Client code generation and documentation
Connect your Bridge API to Bridge Studio
With the CLI
terminalbashnpx bridge-studio@latest# orpnpx bridge-studio@latest
terminalbashnpx bridge-studio@latest# orpnpx bridge-studio@latest
With the plateform: https://studio.bridge.codes
Fetch your client SDK
terminalbashnpx fetch-bridge-sdk@latest {username}/{projectName}
terminalbashnpx fetch-bridge-sdk@latest {username}/{projectName}
Access your generated documentation
You'll be able to access your complete generated documentation on https://studio.bridge.codes soon.
Please visit https://bridge.codes/studio for more information.