未加星标

#Headless CMS using C#, #NodeJS or #Java

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

#Headless CMS using C#, #NodeJS or #Java

Headless Content Management ( https://www.headlesscontentmanagement.com/ ) is a service that decouples the work typically done by content writers and developers. It is designed for use in situations where the content is not going to be viewed on a web-page, but instead is going to be displayed within a mobile app or desktop application.

There are many CMS systems out there, and most of them have APIs. Your content team are probably familiar with the likes of WordPress, Joomla and Dotnetnuke but most operate on the premise that the content is going to be viewed on a web page via a web browser. Headless Content Management makes no such assumption, and won’t help you display your content online it just exposes the content via a set of APIs, XML and JSON based.

Headless CMS can also be used in situations where you have an existing website that isn’t based on a CMS platform like WordPress / Joomla etc. So if you have a in-house developed bespoke website, and need to make it easy for content writers to add and edit content on your website. You can use Headless Content Management to manage your content, then have your existing website call our APIs, in order to retrieve the content to be displayed.

The interface with HeadlessContentManagement.com can be done via many different languages, here are three popular examples C#, NodeJS and Java

C#

// You need to make a service reference to https://HeadlessContentManagement.com/api.asmx

var api = new api.APISoapClient();

// Replace the username and password with those defined on HeadlessContentManagement.com

var strUsername = “[email protected]”;

var strPassword = “demo”;

Console.WriteLine(“Select one of the following articles by it’s id number”);

var articles = api.ListArticles(strUsername, strPassword);

foreach(var article in articles)

{

Console.WriteLine(string.Format(“{0}. {1}”, article.id, article.subject));

}

// Ask the user to enter a number

var strId = Console.ReadLine();

var intArticleId = Convert.ToInt32(strId);

// Get that one Article

var selectedArticle = api.ReadArticle(strUsername, strPassword, intArticleId);

Console.WriteLine(selectedArticle.body);

Console.ReadLine();


#Headless CMS using C#, #NodeJS or #Java
NodeJS

var request = require(‘request’); // run npm install request

var email = ‘[email protected]’;

var password = ‘demo’;

request.post(

‘ https://www.headlesscontentmanagement.com/ajax/ListArticles.aspx&#8217 ;,

{form:{email:email,password:password}},

function (error, response, body) {

if (!error && response.statusCode == 200) {

showArticleSummary(JSON.parse(body));

}

else

{

console.log(response.statusCode);

console.log(body);

}

}

);

function showArticleSummary(Articles)

{

console.log(“Please Select one of the following article ids”);

for(var i in Articles)

{

var Article = Articles[i];

console.log(Article.id + “. ” + Article.subject);

}

process.stdout.write(“>”)

var stdin = process.openStdin();

stdin.addListener(“data”, function(d) {

var strArticleId = d.toString().trim();

var intArticleId = parseInt(strArticleId);

process.stdin.pause();

ReadArticle(intArticleId);

});

}

function ReadArticle(intArticleId)

{

request.post(

‘ https://www.headlesscontentmanagement.com/ajax/ReadArticle.aspx&#8217 ;,

{form:{email:email,password:password, id:intArticleId}},

function (error, response, body) {

if (!error && response.statusCode == 200) {

console.log(JSON.parse(body).body);

}

else

{

console.log(response.statusCode);

console.log(body);

}

}

);

}


#Headless CMS using C#, #NodeJS or #Java
Java

import java.net.HttpURLConnection;

import java.net.URL;

import java.net.MalformedURLException;

import java.io.IOException;

import java.io.*;

import org.json.JSONException;

import org.json.JSONObject;

public class HeadlessContentManagement {

public static void main(String[] args) {

String strJson = getJson(“ https://www.headlesscontentmanagement.com/ajax/ListArticles.aspx&#8221 ;, “[email protected]&password=demo”);

System.out.println(strJson);

}

public static String getJson(String serverUrl,String param){

StringBuilder sb = new StringBuilder();

String http = serverUrl;

HttpURLConnection urlConnection = null;

try {

URL url = new URL(http);

urlConnection = (HttpURLConnection) url.openConnection();

urlConnection.setDoOutput(true);

urlConnection.setRequestMethod(“POST”);

urlConnection.setUseCaches(false);

urlConnection.setConnectTimeout(50000);

urlConnection.setReadTimeout(50000);

urlConnection.connect();

OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());

out.write(param);

out.close();

int HttpResult = urlConnection.getResponseCode();

if (HttpResult == HttpURLConnection.HTTP_OK) {

BufferedReader br = new BufferedReader(new InputStreamReader(

urlConnection.getInputStream(), “utf-8”));

String line = null;

while ((line = br.readLine()) != null) {

sb.append(line + “\n”);

}

br.close();

return sb.toString();

} else {

System.out.println( urlConnection.getResponseMessage());

}

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (urlConnection != null)

urlConnection.disconnect();

}

return null;

}

}

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: C#JavaXMLHeadWord
分页:12
转载请注明
本文标题:#Headless CMS using C#, #NodeJS or #Java
本站链接:http://www.codesec.net/view/561323.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(38)