Socket.IO
Socket.IO is a library that enables low-latency, bidirectional, and event-based communication between clients and servers.
Creating a New Socket.IO Endpoint
Apidog version must be 2.7.0 or higher.
Listening to Events
Open theEvents
tab and enter the event name you want to listen to (e.g., new message
). If you disableListen
for a specific event, you will no longer receive messages for that event.
Event Listening Rules:
- By default, the system listens to the
message
event. - Adding or removing events dynamically does not affect existing connections.
- Changing an event name automatically stops listening to the original event.
Sending Messages
Events & Argument
Ack
When you enable theAck
option, the server sends back a callback message after receiving and processing the request.
Multiple Arguments
Click+ Add Argument
to include additional arguments.
When you send a message with multiple arguments, the timeline will display a label like "x Args". Click on it to expand and view all arguments. You can also switch between tabs on the right for more details.
Handshake Request Parameters
You can include request parameters in theURL
,Params
,Headers
, or Cookies
.
Client Version and Handshake Path
Using Variables
Apidog enables you to include variables in your arguments. When you send a message, these variables are automatically replaced with their real values.
Saving the Endpoint
Once the debugging is complete, click theSave
button to store the Socket.IO endpoint in the HTTP project’s folder tree. This makes it easy for team members to access, debug, and view the endpoint documentation, improving collaboration and efficiency.
Generating the Endpoint Documentation
Easily manage your Socket.IO endpoint by setting its status
, assigningmaintainer
, and adding relevanttags
. You can also write detailed descriptions usingMarkdown
. With Apidog, you can generate online API documentation and share the URL with your team for seamless collaboration.
FAQs
Checklist:
- Make sure the server is running.
- Verify that the client version is compatible with the server.
- Ensure the firewall isn't blocking the required port.
- Review the server's argument handling logic. Example:
socket.on('event', (...args) => {
const callback = typeof args[args.length - 1] === 'function'
? args.pop()
: null;
// // Process the args
});
- Double-check the argument order and types.