REST

161

Solutions

338

Contributors

Representational state transfer (REST) is an architectural style that gives a coordinated set of constraints to the design of components in a distributed hypermedia system used to design networked applications. RESTful systems typically communicate over Hypertext Transfer Protocol (HTTP) with the same HTTP verbs (GET, POST, PUT, DELETE, etc.) that web browsers use to retrieve web pages and to send data to remote servers. REST interfaces with external systems using resources identified by Uniform Resource Identifier (URI) that can be operated upon using standard verbs.

Share tech news, updates, or what's on your mind.

Sign up to Post


Below is my code.
Web-sphere context path is set to simple slash /.

xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 version="3.0">
 <servlet>
    <servlet-name>RestServlet</servlet-name>
    <servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>RestServlet</servlet-name>
    <url-pattern>/users/*</url-pattern>
</servlet-mapping>
</web-app>

Open in new window



appln

package com.ibm.jaxrs.sample;

import java.util.HashSet;
import java.util.Set;

import javax.json.JsonWriter;
import javax.ws.rs.ApplicationPath;

@ApplicationPath("/users")
public class HelloWorldAppConfig extends javax.ws.rs.core.Application {
	   
	   public Set<Class<?>> getClasses() {
	      HashSet<Class<?>> set = new HashSet<Class<?>>();
	      set.add(HelloWorldResource.class);
	      System.out.println("Completed application getclasses");
	      return set;
	   }

}

Open in new window



resource

package com.ibm.jaxrs.sample;

import javax.ws.rs.core.*;
import javax.ws.rs.*;
import javax.servlet.http.HttpServletRequest;

import javax.ws.rs.core.Application;

@javax.ws.rs.Path("/show")
public class HelloWorldResource {

	private static final String LINK_SELF = "self";
	public HelloWorldResource() {
		// TODO Auto-generated constructor stub
    	System.out.println("Got inside constructor");
	}
	
	@GET
	@POST
    @Produces(MediaType.TEXT_PLAIN)
	@Path("/show")
    public Response getAll(@Context UriInfo uriInfo) {
		System.out.println("Completed application getsingleton");
        return Response.ok("Hello").build();
    }//@Produces( MediaType.APPLICATION_JSON )
	
 }

Open in new window



included jars in WEB-INF\lib foler


com.ibm.jaxrs2.0.thinclient_9.0.jar
com.ibm.jaxws.thinclient_9.0.jar
com.ibm.ws.ejb.portable_9.0.jar
com.ibm.ws.ejb.thinclient_9.0.jar
com.ibm.ws.jaxrs20.tools.jar
cxf-rt-frontend-jaxrs-3.1.12.jar
cxf-rt-rs-client-3.1.12.jar
cxf-rt-rs-extension-providers-3.1.12.jar
cxf-rt-rs-extension-search-3.1.12.jar
cxf-rt-rs-json-basic-3.1.12.jar
javax.ws.rs-api-2.0.jar

Open in new window

0
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Dear Sirs,
Below is a Jersey code.  I would like to set the functionality in my Spring REST application. The code filters requests and abort if necessary.
@Provider
public class MyFilterServerRequestAuth implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext requestcontext) throws IOException {
        
        String apikey = requestcontext.getHeaderString("x-api-key");
        String apisecret = requestcontext.getHeaderString("x-api-secret");
        
        if (!FingerAppSettings.API_KEY.equalsIgnoreCase(apikey) || !FingerAppSettings.API_SECRET.equalsIgnoreCase(apisecret)) {
            MyResponseEntity entity = new MyResponseEntity(
                    Response.Status.UNAUTHORIZED.getStatusCode(),
                    MyAppDictionary.getMessageAccessDenied(),
                    requestcontext.getUriInfo().getAbsolutePath()
            );

            requestcontext.abortWith(
                    Response
                            .status(Response.Status.UNAUTHORIZED)
                            .entity(entity)
                            .type(MediaType.APPLICATION_JSON)
                            .build()
            );
        }

    }

}

Open in new window

0
I dont want to re-invent the wheel and build a new WCF or Rest webservice. Please advise, how can I find out if the service I need has already been created by someone? I would love to be able to re-use that WCF/Rest service.

Example: I need a service that would convert currencies.

Thanks,
Ricky
0
I have a web part page displaying 5 web parts. Four of the web parts (Efforts, Phases, Capture Points & Areas) are "provider" web parts, and come from lists that are the sources of 4 lookup columns in the 5th "consumer" web part (Lessons Learned).

The provider web parts are displaying the Title column from the lists.

The Using Javascript/jQuery, I "connected" the 4 provider web parts to the consumer web part, such that when you click on a Title column value, the consumer web part is filtered to show only those records that have the clicked value in the relevant metadata column.

All that is working very nicely.

Now, my requirement is to go one step further, and display the number of items that will be displayed if you click on a Title column value in any of the 4 web parts. If there are none, a "0" should be displayed.

I've constructed a lists service query that successfully returns the number of items that exist for a given, hard-coded, metadata value:
[SiteURL]/_vti_bin/listdata.svc/[ListName]/$count?&$filter=Effort/Title eq 'AAA'

So, the goal is to display such an item count beside the corresponding provider web part value, such as:
Efforts web part:
AAA (10) //assuming there are 10 items in the consumer web part tagged with Effort 'AAA'

Now, I'm bumping up against the current limit of my abilities.

I know that I need code (javascript, rest, ajax, json) for each provider web part with looping to cycle through all of the TD cells that have …
0
i am new to rest api.
i want to implement REST API for my project which is developed with Spring framework.
i want to implement  REST API in best way.

Please provide sugggistions for design and development.
0
I'm trying to implement a restful architecture using .NET Core based on HATEOAS.

For that, I would be using an include parameter with a list in the GET requests so as to include the entities related to the parent.

For example, if I want to get a master (master/details) with the related client I would perform the following GET request:

GET http://api.com/master/id=1?include=Client

Open in new window

If the include clause is not there, the related client in the master will only show the link to get it.

The will happen with every related entity.

What I'm trying to find out is the best way to implement this in my base resource's class.

The solution I applied is to use a base class using generics:

public class InstanceResource<T> where T : BaseResource
{
    public string Href { get; set; }

    public string ClassName { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public T Object { get; set; }
}

Open in new window

Using this, I will have a Master with a InstanceResource related to it.

The object property of InstanceResource<Client> is the actual Client object. If Client is not included in the Include clause of the GET request, the object will be null and it will only show Href and ClassName.

GET http://api.com/master/id=1?include=Client
{
  "object": {
    "client": {
      "object": {
        "name": "JOHN DOE"
      },
      "href": "http://api.com/client/1",
      "className": "Client"
    },
    "details": {
      "href": "http://api.com/details/masterId=1",
      "className": "Collection<Detail>"
    }
  },
  "href": "http://api.com/master/1",
  "className": "Master"
}

Open in new window

Not included Client:

GET http://api.com/master/id=1

{
  "object": {
    "client": {
      "href": "http://api.com/client/1",
      "className": "Client"
    },
    "details": {
      "href": "http://api.com/details/masterId=1",
      "className": "Collection<Detail>"
    }
  },
  "href": "http://api.com/master/1",
  "className": "Master"
}

Open in new window

As you can see, this approach uses a container class to represent the resource. What I need to know if this solution has any disadvantage.

I saw other solutions where all the properties of the Object are at the same level that Href. Something like this:


Open in new window

0
I need to create a set of InfoPath forms and upload them with updated data to a document library.  I have put together some JavaScript which accomplishes this, but the upload of the document (InfoPath doc) is async and the code works fine when I run it in the debugger, but if I run the loop with no breakpoints, the browser hangs on the create/upload of the file.

I am not sure if it is that the function is async or that it appears to be CSOM whereas all my other code is using REST.  

Any help/ideas on this would be greatly appreciated.
0
Hi,

We are developing code in order to do requests to webservices. I am looking  for online webservices that I can use in order to test the next two kind of requests:
- a PUT request
- a request with a HttpHeader

Both SOAP and REST requests.

Anyone a idea for an online application I can use?

Regards,

Arne
0
For two years our vb.net sync app has been running quite successfully hosted on Azure. It gathers recent Db updates and additions from a SQL Db and transposes them on a schedule into the MySQL Db behind a Wordpress site.

The only problem comes when there are two many records to update/add. Then it is prone to either fail or abort in Azure. This happens typically when there are over 500 records to process and the program running time exceeds an hour or two.  We have worked with the Azure team extensively to try and prevent this, but it keeps happening.

We would like to experiment working with the Wordpress REST Api therefore, to see whether time is saved, and efficiency is improved, over the app's current direct SQL calls to the MySQL Db.

The thing is, I'm struggling to find any documentation about how to incorporate the WP REST Api calls in a VB.net application. Does anyone have any examples of how this should be done?

Thank you
0
Dear Sirs,
I have a web app rendering html and exposing at the same time some REST end points.
I have 2 two classes annotated with @ControllerAdvice:
1) A Class will manage all the errors generated on the web side of the application, and redirects to an Error view page
2) The other Class will manage all the errors generated on the REST side of the application and returns an ResponsEntity<Object>

I have some custom exceptions such as NotFoundException, AccessDeniedException, etc.. And there is a generic ExceptionHandler for the Class Exception.class in both the 2 @ControllerAdvice Classes: 1 for web side exception and 1  for REST side exception.

The confusion  I am seeing is that when the generic exception occurs, while I am consuming the REST end points, I will get an HTML error view instead of a Jackson string representing the ResponseEntity<Object> and vice-versa.

How can I handle this. Make @ControllerAdvice Class 1 only look at exceptions generated by all the classes annotated with @Controller, and @ControllerAdvice Class 2 only look at exceptions generated by all the classes annotated with @RestController.


Thanks a in advance
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE
LVL 4
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Dear sirs,

I have CSRF enabled in my REST application.
I use either RestTemplate or Postman as Client.
How can I set the application in a way that each request (POST/PUT/DELETE) is carried with a token in its header.

I remember using an implementation of  ContainerRequestFilter while working on Jersey, and I could take care of my requests globally.

I am looking forward to hearing from you.
0
I have a user form that is created in extjs framework. The user form has many user fields which are being passed as part of request payload to the REST controller. I am trying to add a grid panel(most likely in a tabular format with multiple rows & columns) to the user form. But I am not sure how to pass the grid panel data as part of request payload to the REST controller. I will post more code if any more details are needed. Any help would be appreciated. Thanks.

Ext.define('soylentgreen.view.admin.UserForm', {
    extend : 'Ext.form.Panel',
    alias : 'widget.userform',
    bodyStyle : 'padding:5px 5px 0',

// some userform elements like firstname,lastname, go here.....

name : 'userTeamGrid',
  xtype : 'gridpanel',
id : 'userTeamGrid',
itemId : 'userTeamGrid',
multiSelect : true,
selModel : Ext.create(
        'Ext.selection.CheckboxModel',
        {
          injectCheckbox : 'first',
          mode : 'MULTI',
          checkOnly : false
        }),
anchor : '100%',
width : '700px',
height : 250,
flex : 1,
store : 'userTeamStore',

var user = form.getRecord();
form.updateRecord(user);
user.save({
        callback : function(records, operation){
          //reset the (static) proxy extraParams object
          user.getProxy().extraParams =  {
            requestType: 'standard'
          }
          if(!operation.wasSuccessful()){
            var error = operation.getError();
0
I have an XML file that when passed through SOAP UI returns a proper response as XML file. I need to create an application to pass the XML and recuperate the response. I tried searching but many say REST web service where they using only post/get.

Please send me some sample code and/or tutorials.
0
I am exporting a table using pdfmake
The table exports, but there is one item that is 'undefined'.  

I have a main page with multiple tabs and once you hit the 'Printer Friendly' btn, a pdf report opens in a new tab for the specific tab you selected.  The 'printer friendly' btn is what exports the page.  

This code broadcasts  the print function to produce the pdf report depending on what tab you are on.
$scope.printDiv = function(divName) {		
		$rootScope.$broadcast('print');		
	}
	

Open in new window


and the button
<button ng-click="printDiv('rollup-tab')">Printer Friendly</button>

Open in new window



Here is the rest of the code.

Table creation and exports the pdf pdf
$scope.$on('print', function(event, filter) {
			var docDefinition = {

					content: [	
					          {
						  table: {

					              body: [                   			                
					                [ 
					                  '',
					                  'Actual Pieces Issued',
					                  {text: $filter('mcGoalNumberFilter')($scope.actualPiecesMCGoal) + ' /wk'},			                  
					                  {text: $scope.actualPiecesMon, style: 'tableData'},
					                  {text: $scope.actualPiecesTues, style: 'tableData'},
					                  {text: $scope.actualPiecesWed, style: 'tableData'},
					                  {text: $scope.actualPiecesThurs, style: 'tableData'},
					                  {text: $scope.actualPiecesFri, style: 

Open in new window

0
i want to send email notification to few external users .

Tried using designer 2013 /2010 workflow.

Also tried JSom code using Rest Api
0
Hello Guys , i need a GPO for work life balance , just locking computer automatically after 4 hrs of activity and unlock it after 10 min of rest
0
I am working with excel 2007 and I have changed my printer settings, selected all then changed the page set up, changed in print settings while under print entire workbook. All three option print the first page in color and the rest black and white and double sided. Right now I am going tab by tab to update the page setup - is there a better way to do this though.
0
Dears,
Some servers over the network I can open normally like \\severname\c$ with no issue but the rest of the servers I can't like I don't connect to the network.
I have windows 10 and this is normal netwrok with Microsoft active directory. The other machine I can connect and do it by my users to access all servers but not from my machine anymore.
Regards
Mostafa
0
websites provide android app fetching from rest api.
websites provide  rest api using c# with just one controller in project and sql server 2016 sending/receiving data for one table.
So these are not compact,efficient for complete project with multiple tables.
I am very curious to have modular code for all these concepts.
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Why can't we write an efficient query to check if any results are not started with a set of alphabets? I am using this https://wordpress.org/plugins/alphabetic-pagination/ but i don't know that how can i check if rest of the alphabets are not having any results in it.
0
I am not a .net developer but work with PowerShell a bit.

Is this a process that is even possible and if so how do i get it done?

Thank you
0
Hi there:
Im working with an old project developed in delphi7 and am facing a problem with a TMonthCalendar componet. My goal is when the user press for example the up arrow key over the monthcalendar the date decreases 7 days, if presses the down key arroy instead, the date increases 7 days and so on. The problem is that when i try to capture those keys on the mousedown event i haven't a response on that particulars keys, working normally for the rest. Thanks in advance,
Klueze.
0
I need to find a way to patch my servers by function.  I want to patch the dev/test server, wait a week, patch the QA /staging servers, wait a week then patch the production servers.  This will allow the application support teams to verify  the patching didnt break their applications before being rolled out to the next level.   Same for the workstations.  Patch the Beta group of users, wait a week and then patch the rest.

Waiting to approve the patches doesnt fix my issue and the GPO only allows for a specific date.  Any ideas?  Btw:  Servers are 2012 R2 and desktops are Windows 10 pro.

Thanks,

Donna
0
Hi ,

I am trying to download an excel file using REST API. But I am getting the file in binary format. Please help.

I have tried with curl/wget.

Many Thanks
0
I have seen some snippets where the code uses a combination of Name/Title and $Expand to get more columns back from a REST call.  Can someone describe how to use these facilities to avoid making multiple calls to get back values?
0

REST

161

Solutions

338

Contributors

Representational state transfer (REST) is an architectural style that gives a coordinated set of constraints to the design of components in a distributed hypermedia system used to design networked applications. RESTful systems typically communicate over Hypertext Transfer Protocol (HTTP) with the same HTTP verbs (GET, POST, PUT, DELETE, etc.) that web browsers use to retrieve web pages and to send data to remote servers. REST interfaces with external systems using resources identified by Uniform Resource Identifier (URI) that can be operated upon using standard verbs.

Top Experts In
REST
<
Monthly
>