浏览代码

Improved formatting of new networking manuals

Björn Ritzl 5 年之前
父节点
当前提交
5fa6b1eff9
共有 3 个文件被更改,包括 28 次插入8 次删除
  1. 21 5
      docs/en/manuals/http-requests.md
  2. 6 2
      docs/en/manuals/socket-connections.md
  3. 1 1
      docs/en/manuals/websocket-connections.md

+ 21 - 5
docs/en/manuals/http-requests.md

@@ -5,7 +5,11 @@ brief: This manual explains how to make HTTP requests.
 
 ## HTTP requests
 
-Defold can make normal HTTP requests using the `http.request()` function. Example:
+Defold can make normal HTTP requests using the `http.request()` function.
+
+### HTTP GET
+
+This is the most basic request to get some data from the server. Example:
 
 ```Lua
 local function handle_response(self, id, response)
@@ -17,7 +21,13 @@ http.request("https://www.defold.com", "GET", handle_response)
 
 This will make an HTTP GET request to https://www.defold.com. The function is asynchronous and will not block while making the request. Once the request has been made and a server has sent a response it will invoke/call the provided callback function. The callback function will receive the full server response, including status code and response headers.
 
-It is also possible to make HTTP POST requests to pass data to the server and to specify request headers:
+::: sidenote
+HTTP requests are automatically cached in the client to improve network performance. The cached files are stored in an OS specific application support path in a folder named `defold/http-cache`. You usually don't have to care about the HTTP cache but if you need to clear the cache during development you can manually delete the folder containing the cached files. On macOS this folder is located in `%HOME%/Library/Application Support/Defold/http-cache/` and on Windows in `%APP_DATA%/defold/http-cache`.
+:::
+
+### HTTP POST
+
+When sending data, like a score or some authentication data, to a server it is typically done using a POST requests:
 
 ```Lua
 local function handle_response(self, id, response)
@@ -31,8 +41,14 @@ local body = "foo=bar"
 http.request("https://httpbin.org/post", "POST", handle_response, headers, body)
 ```
 
+### Other HTTP methods
+
+Defold HTTP requests also support the HEAD, DELETE and PUT methods.
+
+### API Reference
+
 Refer to the [API reference](/ref/http/) to learn more.
 
-::: sidenote
-HTTP requests are automatically cached in the client to improve network performance. The cached files are stored in an OS specific application support path in a folder named `defold/http-cache`. You usually don't have to care about the HTTP cache but if you need to clear the cache during development you can manually delete the folder containing the cached files. On macOS this folder is located in `%HOME%/Library/Application Support/Defold/http-cache/` and on Windows in `%APP_DATA%/defold/http-cache`.
-:::
+### Extensions
+
+An alternative HTTP request implementation can be found in the [TinyHTTP extension](https://defold.com/assets/tinyhttp/).

+ 6 - 2
docs/en/manuals/socket-connections.md

@@ -5,7 +5,7 @@ brief: This manual explains how to connect to create socket connections.
 
 ## Socket connections
 
-Defold includes the [LuaSocket library](http://w3.impa.br/~diego/software/luasocket/) for creating TCP and UDP socket connections. Creating a socket connection, sending some data and reading a response is a little bit more involved:
+Defold includes the [LuaSocket library](http://w3.impa.br/~diego/software/luasocket/) for creating TCP and UDP socket connections. Example of how to create a socket connection, sending some data and reading a response:
 
 ```Lua
 local client = socket.tcp()
@@ -15,4 +15,8 @@ client:send("foobar")
 local response = client:receive("*l")
 ```
 
-This will create a TCP socket, connect it to IP 127.0.0.1 (localhost) and port 8123. It will set timeout to 0 to make the socket non-blocking and it will send the string "foobar" over the socket. It will also read a line of data (bytes ending with a newline character) from the socket. Note that the above example doesn't contain any kind of error handling. Refer to the [API reference](/ref/socket/) to learn more about the functionality available via LuaSocket. The [official LuaSocket documentation](http://w3.impa.br/~diego/software/luasocket/) also contains many examples of how to work with the library. There is also some examples and helper modules in the [DefNet library](https://github.com/britzl/defnet/).
+This will create a TCP socket, connect it to IP 127.0.0.1 (localhost) and port 8123. It will set timeout to 0 to make the socket non-blocking and it will send the string "foobar" over the socket. It will also read a line of data (bytes ending with a newline character) from the socket. Note that the above example doesn't contain any kind of error handling.
+
+### API Reference and examples
+
+Refer to the [API reference](/ref/socket/) to learn more about the functionality available via LuaSocket. The [official LuaSocket documentation](http://w3.impa.br/~diego/software/luasocket/) also contains many examples of how to work with the library. There is also some examples and helper modules in the [DefNet library](https://github.com/britzl/defnet/).

+ 1 - 1
docs/en/manuals/websocket-connections.md

@@ -4,4 +4,4 @@ brief: This manual explains how to use WebSocket connections.
 ---
 ## WebSocket connections
 
-Defold doesn't contain any out of the box solution for creating WebSocket connections. For WebSocket connectivity it is recommended to use the [Defold-WebSocket extension](https://github.com/britzl/defold-websocket).
+Defold doesn't contain any out of the box solution for creating WebSocket connections. For WebSocket connectivity it is recommended to use the [Defold-WebSocket extension](https://defold.com/assets/websocket/).