Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleBeispiel
package example.rest;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Providerws.rs.GET;
import javax.ws.rs.GETPath;
import javax.ws.rs.PathProduces;

import javaxorg.wsnuclos.rsapi.Producesrule.CustomRestRule;

@Path("example")
public class CustomRestWithPathTestRule implements CustomRestRule {

	@GET
	@Path("customers")
	@Produces("application/json")
	public List<Customer> customers() {
		return Arrays.asList(
				new Customer(1, "Mustermann"),
				new Customer(2, "Maier")
		);
	}

	public static class Customer {
		private int id;
		private String name;

		public Customer(final int id, final String name) {
			this.id = id;
			this.name = name;
		}

		public int getId() {
			return id;
		}

		public String getName() {
			return name;
		}
	}
}

...

Code Block
languagejava
titleContext
@Inject
protected Provider<CustomRestContext> context;

// Dazu müssen noch zweidrei weitere Klassen importiert werden:

import orgjavax.nuclos.api.rule.CustomRestRuleinject.Inject;
import javax.inject.Provider;
import org.nuclos.api.context.CustomRestContext;

...