Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

License

NotificationsYou must be signed in to change notification settings

karandaid/sapix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAPIX:SimpleAPIProcessing andIntegration eXperience

Welcome toSapix, a lightweight library designed to help you build robust servers with intuitive routing. This documentation provides examples and instructions to get you started usingSapix effectively.


Installation

InstallSapix via npm:

npm install sapix

Usage Overview

Below is an example of setting up a server usingSapix and configuring multiple routes with different HTTP methods.


Step-by-Step: Create Routes with Sapix

GET/ – Home Route

routes.get('/',(res)=>{res.status(200).sendText('Welcome to sapixRoutes Home Page!');});
  • Purpose: Handles the homepage request and responds with text.
  • Response:
    Welcome to sapixRoutes Home Page!

GET/profile/:id/user/:userId – Dynamic Route with Params

routes.get('/profile/:id/user/:userId',(res,query,path_params)=>{res.status(200).sendJSON({message:'This is a JSON response.',         query,         path_params});});
  • Purpose: Responds with JSON including query and path parameters.
  • Example Request:
    GET /profile/1/user/456?status=active
  • Example Response:
    {"message":"This is a JSON response.","query": {"status":"active" },"path_params": {"id":"1","userId":"456" }}

HTTP Method Examples

POST/profile – Create User Profile

routes.post('/profile',(res)=>{res.status(200).sendJSON({message:'Profile created successfully.'});});
  • Purpose: Responds toPOST requests with a confirmation message.
  • Response:
    {"message":"Profile created successfully." }

DELETE/profile – Delete User Profile

routes.delete('/profile',(res)=>{res.status(200).sendJSON({message:'Profile deleted successfully.'});});
  • Purpose: Responds with a message confirming deletion.
  • Response:
    {"message":"Profile deleted successfully." }

PATCH/profile – Update User Profile

routes.patch('/profile',(res)=>{res.status(200).sendJSON({message:'Profile updated successfully.'});});
  • Purpose: Responds with a message confirming the profile update.
  • Response:
    {"message":"Profile updated successfully." }

Additional Routes

GET/about – About Page

routes.get('/about',(res)=>{res.status(200).sendHTML('<h1>Welcome to the About Page!</h1>');});
  • Purpose: Sends an HTML response for the "About" page.
  • Response:
    <h1>Welcome to the About Page!</h1>

GET/error – Error Handling

routes.get('/error',(res)=>{res.sendError('An unexpected error occurred.',500);});
  • Purpose: Simulates a server error response.
  • Response:
    {"error":"An unexpected error occurred." }

Starting the Sapix Server

Once your routes are defined, start the server using the following code:

import{sapixServer,sapixRoutes}from'sapix';// Create routesconstroutes=newsapixRoutes();// Start the serverconstserver=newsapixServer().setPort(4000)// Specify the port.setRoute(routes)// Attach the routes.start();// Start the server

Your server will now be running athttp://localhost:4000.


Key Features of Sapix

  1. Simple: Easy to configure with minimal setup.
  2. API-oriented: Focused on building APIs efficiently.
  3. Processing-friendly: Handles different HTTP methods (GET, POST, PATCH, DELETE).
  4. Integrated: Supports dynamic routes, query params, and path params.
  5. Xperience-first: Provides error handling and a smooth developer experience.

Project Structure

├── index.js           // Main server script└── package.json       // Project metadata and dependencies

How to Test

  • GET Request:
    Visithttp://localhost:4000/profile/1/user/456 in your browser or Postman.

  • POST Request:
    Send aPOST request tohttp://localhost:4000/profile with an appropriate payload.


Error Handling

UsesendError to return error responses:

routes.get('/error',(res)=>{res.sendError('Something went wrong!',500);});

Feedback & Contribution

Feel free to contribute to this project by submitting pull requests or opening issues.


License

This project is licensed under theMIT License.


Enjoy theSimple API Processing and Integration eXperience with Sapix! 🚀

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp