ZEP Guidebook (EN)
  • Hello ZEP Script
  • ZEP Script
    • πŸ’»ZEP Script Guide
      • ZEP Script Development Guide
        • JavaScript Development Tips
        • ZEP Script Deployment Guide
        • TypeScript Development Tips
      • Explore ZEP Script
        • Tutorials
          • Displaying a Message
          • Changing Avatar Image
          • Using HTML
          • Communicating with an External API
          • Creating a 2-Second Stun Effect
        • ZEP Script Example Code
          • Timer
          • Zombie Game
          • Paintman Game
          • Hangul Quiz Game
          • Avoid Poop Game
          • Boxing Game
          • Sidebar App
          • Race
      • ZEP Script FAQ
      • Appendix
        • ZEP Script Use Cases
        • Understanding Spaces and Maps
        • JavaScript Keycode List
        • Understanding Sprite Sheets
        • TileEffectType Detailed Explanation
        • What are Reference Coordinates?
        • Communicating with an External API
        • How to Use URL Query Strings
        • How to Change the Mobile Interaction Button
        • Grammar Available for Widgets
        • Object Interaction with ZEP Script
        • Object npcProperty
    • πŸ“˜ZEP Script API
      • API Summary
      • ScriptApp
        • Lifecycle
        • Field
        • Storage
        • Event Listeners
        • Callbacks
        • Methods
      • ScriptMap
        • Field
        • Methods
      • ScriptPlayer
        • Field
        • Methods
      • ScriptWidget
        • Field
        • Event Listeners
        • Methods
  • Others
    • Homepage
    • FAQ
    • Twitter
    • Discord
Powered by GitBook
On this page
  • httpGet
  • httpPost

Was this helpful?

  1. ZEP Script
  2. ZEP Script Guide
  3. Explore ZEP Script
  4. Tutorials

Communicating with an External API

PreviousUsing HTMLNextCreating a 2-Second Stun Effect

Last updated 2 years ago

Was this helpful?

You can send GET, POST, etc. requests with arguments to an external API.

httpGet

Changes the nicknames of the users who have just entered with the API.

// Executes when a player enters
App.onJoinPlayer.Add(function (player) {
	App.httpGet(
		"https://nickname.hwanmoo.kr/?format=json&count=1&max_length=6&whitespace=_",
		null,
		function (res) {
			// Change the response to a JSON object
			let response = JSON.parse(res);
			player.name = response.words[0];
			player.sendUpdated();
		}
	);
});

httpPost

Receives the header and data sent from the app in response and displays it in the chat window.

// Activates function when q is pressed
App.addOnKeyDown(81, function (player) {
	App.httpPost(
		"https://postman-echo.com/post",
		{
			"test-header": "zep",
		},
		{
			name: "zepscript",
		},
		(res) => {
			let response = JSON.parse(res);
			App.sayToAll(`header sent: ${response.headers["test-header"]}`, 0xffffff);
			App.sayToAll(`data sent: ${response.form.name}`, 0xffffff);
		}
	);
});

Please Note

- For the tutorial, we recommend setting the app type to Mini-Game.

- The JSON file name must be β€œmain.” Please create a new text file and name it β€œmain.js.”


- If you do not know how to deploy an app, please refer to the .

πŸ’»
ZEP Script Deployment Guide
Korean Nickname Generator