Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6951337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:12:24+00:00 2026-05-27T14:12:24+00:00

I need to create a rest server and client. I stumbled upon this tutorial

  • 0

I need to create a rest server and client.

I stumbled upon this tutorial which uses sockets. I want to be able to use REST calls, possibly HTTP, because the clients will be actually in different languages.

Instead of using Socket api from java.net.* what should i use ? if i use Socket API can I use c++ and php to communicate with this server? or should i go with REST?

any directions appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:12:24+00:00Added an answer on May 27, 2026 at 2:12 pm

    There’s a lot of things you can use to create rest services, and then they can be consumed by almost anything. Of particular awesomeness is the ability to hit them in your web browser, just because we’re all so familiar with them.

    When I need a ‘quick and dirty’ rest solution, I use Restlet – I won’t claim it’s the only solution, but it’s the easiest I’ve ever worked with. I’ve literally said in a meeting “I could have XYZ up in 10 minutes.” Someone else in the meeting called me on it, and sure enough, using Restlet I was able to get a functioning REST server running with the (very simple) features I said I would get in the meeting. It was pretty slick.

    Here’s a barebones server that has one method, returning the current time. Running the server and hitting 127.0.0.1:12345/sample/time will return the current time.

    import org.restlet.Application;
    import org.restlet.Component;
    import org.restlet.Context;
    import org.restlet.Restlet;
    import org.restlet.data.Protocol;
    import org.restlet.routing.Router;
    
    /**
     * This Application creates an HTTP server with a singple service
     * that tells you the current time.
     * @author corsiKa
     */
    public class ServerMain extends Application {
    
        /**
         * The main method. If you don't know what a main method does, you 
         * probably are not advanced enough for the rest of this tutorial.
         * @param args Command line args, completely ignored.
         * @throws Exception when something goes wrong. Yes I'm being lazy here.
         */
        public static void main(String...args) throws Exception {
            // create the interface to the outside world
            final Component component = new Component();
            // tell the interface to listen to http:12345
            component.getServers().add(Protocol.HTTP, 12345);
            // create the application, giving it the component's context
            // technically, its child context, which is a protected version of its context
            ServerMain server = new ServerMain(component.getContext().createChildContext());
            // attach the application to the interface
            component.getDefaultHost().attach(server);
            // go to town
            component.start();
    
        }
    
        // just your everyday chaining constructor
        public ServerMain(Context context) {
            super(context);
        }
    
        /** add hooks to your services - this will get called by the component when
         * it attaches the application to the component (I think... or somewhere in there
         * it magically gets called... or something...)
         */
        public Restlet createRoot() {
            // create a router to route the incoming queries
            Router router = new Router(getContext().createChildContext());
            // attach your resource here
            router.attach("/sample/time", CurrentTimeResource.class);
            // return the router.
            return router;
        }
    
    }
    

    And here’s the ‘current time resource’ that it uses:

    import org.restlet.representation.Representation;
    import org.restlet.representation.StringRepresentation;
    import org.restlet.resource.Get;
    import org.restlet.resource.ServerResource;
    
    /**
     * A resource that responds to a get request and returns a StringRepresentaiton
     * of the current time in milliseconds from Epoch
     * @author corsiKa
     */
    public class CurrentTimeResource extends ServerResource {
    
        @Get // add the get annotation so it knows this is for gets
        // method is pretty self explanatory
        public Representation getTime() {
            long now = System.currentTimeMillis(); 
            String nowstr = String.valueOf(now); 
            Representation result = new StringRepresentation(nowstr);
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to create a custom DNS name server using C which will check against
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a linked server to a DB2 database on a mainframe.
I need to create an ASP page (classic, not ASP.NET) which runs remote shell
I need to create a backup of a SQL Server 2005 Database that's only
I need to build a client application that connects to the team foundation server
Do we really need a server side architecture to create a RIA application? My
I need to work with REST api in android application which is created by
I have a REST Server running on Tomcat 5.5. Some of the services need
I have a REST web service that currently exposes this URL: http://server/data/media where users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.