https://github.com/edufolly/nano-api-iot
Nano Java API Server for IoT
https://github.com/edufolly/nano-api-iot
Last synced: 3 months ago
JSON representation
Nano Java API Server for IoT
- Host: GitHub
- URL: https://github.com/edufolly/nano-api-iot
- Owner: edufolly
- Created: 2018-12-23T13:10:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-23T16:36:23.000Z (over 6 years ago)
- Last Synced: 2025-01-13T03:32:52.507Z (5 months ago)
- Language: Java
- Size: 4.08 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nano-api-iot
## How to use:
```java
public static void main(String[] args) {new Nano()
.setPort(8088)
.setMaxConnections(200)
.setCacheDir("cache")
.setPackageName("io.github.edufolly.nano.start.ws")
.setLogConfigurationFile("log4j2.xml")
.setServerName("Nano API IOT Server")
.start();
}
```## Examples:
```java
package io.github.edufolly.nano.start.ws;import io.github.edufolly.nano.annotations.BodyParam;
import io.github.edufolly.nano.annotations.GET;
import io.github.edufolly.nano.annotations.MediaTypeEnum;
import io.github.edufolly.nano.annotations.POST;
import io.github.edufolly.nano.annotations.Path;
import io.github.edufolly.nano.annotations.PathParam;
import io.github.edufolly.nano.annotations.QueryStringParam;
import io.github.edufolly.nano.annotations.ReturnType;
import java.util.HashMap;
import java.util.Map;/**
*
* @author Eduardo Folly
*/
@Path("/api/test")
public class ApiTeste {@GET
@ReturnType(MediaTypeEnum.TEXT)
@Path("/text")
public String testGetText() {
return "Test OK!!";
}@GET
@ReturnType(MediaTypeEnum.HTML)
@Path("/html")
public String testGetHtml() {
StringBuilder sb = new StringBuilder("");
sb.append("");
sb.append("");
sb.append("Test OK!!");
sb.append("");
sb.append("");
sb.append("Test OK!!
");
sb.append("");
sb.append("");
return sb.toString();
}@GET
@ReturnType(MediaTypeEnum.JSON)
@Path("/json")
public Map testGetJson() {
Map map = new HashMap();
map.put("test", "OK!!");
return map;
}@GET
@Path("/null")
public Object testNull() {
return null;
}@GET
@Path("/void")
public void testVoid() {
// Nothing.
}@GET
@Path("/erro")
public Object testException() throws Exception {
throw new Exception("My error message!");
}@GET
@Path("/param/:pint/:pstring")
@PathParam({"pint", "pstring"})
public Map testGetParam(int pint, String pstring) {
Map map = new HashMap();
map.put("test", "OK!!");
map.put("pint", pint);
map.put("pstring", pstring);
return map;
}@GET
@Path("/qs")
@QueryStringParam({"q"})
public Map testGetQueryString(String q) {
Map map = new HashMap();
map.put("test", "OK!!");
map.put("q", q);
return map;
}@POST
@BodyParam
public Map testPost(Map map) {
map.put("test", "OK!!");
return map;
}
}
```