rapid-tsGuide

Universe Example

This is a great example of how to create a Planet API, demonstrating how to structure endpoints, reference IDs, and use enums effectively.

import { RapidServer } from '@rapid-api/rapid-ts';

const options = {
	name: "universe-api",
	port: 3000,
	prefix: "/api",
	endpoints: [
		{
			name: "solar-systems",
			methods: ["GET", "GET_BY_ID", "POST", "PATCH", "DELETE"],
			objectReference: {
				name: "string", // Name of the solar system
				age: "number", // Age of the solar system in billion years
				starType: "enum:starTypes", // Type of star (e.g., G-type, M-type)
				planets: ["id:planets"], // List of planets in this solar system
			},
		},
		{
			name: "planets",
			methods: ["GET", "GET_BY_ID", "POST", "PATCH", "DELETE"],
			objectReference: {
				name: "string", // Name of the planet
				type: "enum:planetTypes", // Planet type (terrestrial, gas giant, etc.)
				diameter: "number", // Diameter in kilometers
				hasLife: "boolean", // Whether life is detected
				moons: ["id:moons"], // List of moons
			},
		},
		{
			name: "moons",
			methods: ["GET", "GET_BY_ID", "POST", "PATCH", "DELETE"],
			objectReference: {
				name: "string", // Name of the moon
				diameter: "number", // Diameter in kilometers
				orbits: "id:planets", // The planet it orbits
			},
		},
	],
	enums: {
		planetTypes: ["Terrestrial", "Gas Giant", "Ice Giant", "Dwarf Planet"],
		starTypes: ["O-type", "B-type", "A-type", "F-type", "G-type", "K-type", "M-type"],
	},
};

const rapidServer = new RapidServer(options);
rapidServer.start();