Kargate Socket.IO APIs

OverviewCopied!

The Kargate Socket.IO API provides real-time updates for notifications and new feeds. The base URL for the API is:

https://devio.kargate.site

All requests require an Authorization header with a Bearer Token, formatted as:

Authorization: Bearer YOUR_TOKEN_HERE

EndpointsCopied!

1. /notification

Event: notification_history

Upon the first connection, the server emits a

notification_history

event, returning the user's past notifications as:

[{
    "date": "2025-03-04T12:00:00Z",
    "noti_title": "New Post Available",
    "noti_type": "PostUploaded",
    "noti_message": "A new car post has been uploaded.",
    "noti_for_user": "user_123",
    "actions": [
        {
            "action_label": "View Post",
            "url": "https://kargate.site/post/456"
        }
    ]
}]
Event: notification

When a new notification arrives for the connected user, the server emits a

notification

event containing a

UserNotification

object:

{
    "date": "2025-03-04T12:30:00Z",
    "noti_title": "Your ID verification was approved!",
    "noti_type": "IdVerifyFormApproved",
    "noti_message": "You are now a verified user.",
    "noti_for_user": "user_123",
    "actions": null
}

2. /newfeeds

Event: newfeeds

Returns an array of posts (Vec<Post> ) which can be either CarPost or PackagePost . The client should check the post_type field to determine the type.

Example response:

[{
    "date": "2025-03-04T13:00:00Z",
    "title": "Available Car for Transport",
    "description": "A truck available from Yangon to Mandalay.",
    "author": "John Doe",
    "author_id": "user_789",
    "post_type": "Car",
    "owner_id": "owner_456",
    "driver_id": "driver_321",
    "car_id": "car_999",
    "start_location_detail": "Yangon, Myanmar",
    "start_location": [16.8409, 96.1735],
    "end_location_detail": "Mandalay, Myanmar",
    "end_location": [21.9162, 95.9560],
    "expected_date_to_start": "2025-03-06T08:00:00Z",
    "post_photos": ["https://kargate.site/img1.jpg"],
    "main_package_types": ["Electronics", "Furniture"],
    "cost_per_type": {
        "Electronics": 5000,
        "Furniture": 7000
    }
}]

Client-Side Implementation ExampleCopied!

JavaScript Implementation

Connecting to the API
const io = require("socket.io-client");

const socket = io("https://devio.kargate.site", {
    extraHeaders: {
        Authorization: "Bearer YOUR_BEARER_TOKEN"
    }
});
Listening for Notifications
socket.on("notification_history", (notifications) => {
    console.log("Past Notifications:", notifications);
});

socket.on("notification", (newNotification) => {
    console.log("New Notification Received:", newNotification);
});
Listening for New Feeds
socket.on("newfeeds", (posts) => {
    posts.forEach(post => {
        if (post.post_type === "Car") {
            console.log("Car Post:", post);
        } else if (post.post_type === "Package") {
            console.log("Package Post:", post);
        }
    });
});

Flutter/Dart Implementation

Connecting to the API
import 'package:socket_io_client/socket_io_client.dart' as io;

void main() {
  final socket = io.io('https://devio.kargate.site', <String, dynamic>{
    'extraHeaders': {'Authorization': 'Bearer YOUR_BEARER_TOKEN'},
    'transports': ['websocket'],
  });

  socket.connect();
}
Listening for Notifications
socket.on('notification_history', (data) {
  print('Past Notifications: $data');
});

socket.on('notification', (data) {
  print('New Notification Received: $data');
});
Listening for New Feeds
socket.on('newfeeds', (data) {
  for (var post in data) {
    if (post['post_type'] == 'Car') {
      print('Car Post: $post');
    } else if (post['post_type'] == 'Package') {
      print('Package Post: $post');
    }
  }
});

ConclusionCopied!

The Kargate Socket.IO API provides a seamless way to receive real-time notifications and updates on new transportation-related posts. By utilizing event listeners, clients can stay up-to-date with the latest changes efficiently.

For more details, contact @linuswalker or visit the Kargate Developer Documentation.